Skip to content

Table mapped structs do not support embedded structs #13

@silasdavis

Description

@silasdavis

If I attempt to map:

type CreatedUpdated struct {
    Created sql.NullInt64 //time.Time
    Updated sql.NullInt64 //time.Time
}

type ExternalSource struct {
    Uuid string
    Name string
    CreatedUpdated
}

With:

dbmap.AddTableWithName(ExternalSource{}, "external_sources")

It will fail with sql: converting Exec argument #2's type: unsupported type models.CreatedUpdated, a struct

This is because the embedded struct walking logic in dbmap.AddTable was removed with the intention to let sqlx handle the scanning.

Somehow we need to extract the logic in sqlx.StructScan and use it here, or if it does not generalise well add back in support for struct scanning in modl.

It also appears much of the bindPlan functionality from gorp has been abandoned, it would be nice to use prepared statements in the bind plan and also use the table mapping to remove as much reflection as possible when running a query. Since we have mapped the table up front I feel we should be able to use something leaner than sqlx.StructScan in Get or other planned queries...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions