canonical / sqlair

Friendly type mapping for SQL databases
Apache License 2.0
17 stars 8 forks source link

Add support for embedded/nested structs #83

Closed Aflynn50 closed 4 months ago

Aflynn50 commented 1 year ago

Add support for embedded/nested structs to SQLair input and output expressions. Embedded structs are structs included without a field name and nested structs are those included with a field name. e.g. embedded:

type S struct {
    E
}

and nested:

type S struct {
    e E
}

A SQLair output expression can now be something like &MyStruct.myfieldtag where the tagged field was nested/embedded multiple layers deep. The tags of the inner structs are referenced as if they were tags of the top level struct. An asterisk expression (e.g. &MyStruct.*) will now include all embedded/nested tagged fields in a struct.

Pointers to nested structs are also handled as above.

If the field containing a nested struct has a tag on it then it will be ignored (unless the struct in the field implements sql.Scanner).

If there are clashing tags between nested structs an error will be returned from Prepare.

Aflynn50 commented 4 months ago

Succeeded by #141