sqlx
sqlx copied to clipboard
Update reflectx to allow for optional nested structs
Nested structs are now only instantiated when one of the database columns in that nested struct is not nil. This allows objects scanned in left/outer joins to keep their natural types (instead of setting everything to NullableX).
Example:
select house.id, owner.*,
from house
left join owner on owner.id = house.owner
Before
type House struct {
ID int
Owner *Person // if left join gives nulls, Owner is set
}
type Owner struct {
ID sql.NullInt64 // make nullable columns even tho if table doesn't have those columns nullable
}
After
type House struct {
ID int
Owner *Person // if left join gives nulls, Owner will be nil
}
type Owner struct {
ID int // no need to set this to sql.NullInt
}