canonical / sqlair

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

Add embedded struct support #141

Closed Aflynn50 closed 3 months ago

Aflynn50 commented 4 months ago

Embedded structs in Go are not automatically promoted to the containing struct. No explicit support for them has been added to SQLair before so they are not currently supported.

This PR adds support for arbitrary levels of embedded structs. All fields in the embedded structs will be promoted to the top level.

You will now be able to do:

type Embedded struct {
  F int `db:"embeddedColName"`
}

type S struct {
  Embedded
}

stmt, err := sqlair.Prepare("SELECT &S.embeddedColName FROM t", S{})

Also: