You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
sqlx supports embedded structs, but pointers to structs are not followed. This is a bug, because it's contrary to reasonable expectations, ie:
typeFoostruct {
Namestring
}
// can set 'Name' on this structtypePlacestruct {
Foo
}
// cannot set 'Name' on this structtypePersonstruct {
*Foo
}
Currently, when you scan into a nil pointer, database/sql allocates the space for you. This is how []byte and string work as well; a new one will always be allocated. I'm going to copy this behavior, even though it's not well known, because I don't want StructScan to behave differently and because I think it could end up creating incredibly difficult to figure out bugs.
The setValues function can allocate these using reflect.
Note that all this per-row allocation is going to cost a little something, so if speed is a priority I recommend against pointer embeds.
The text was updated successfully, but these errors were encountered:
After this patch I receive sql: Scan error on column index 6: destination pointer is nil upon calling StructScan. Just to notify that this brakes some working code. I'll see if I get time for a full bug report later.
sqlx supports embedded structs, but pointers to structs are not followed. This is a bug, because it's contrary to reasonable expectations, ie:
Currently, when you scan into a nil pointer, database/sql allocates the space for you. This is how
[]byte
andstring
work as well; a new one will always be allocated. I'm going to copy this behavior, even though it's not well known, because I don't wantStructScan
to behave differently and because I think it could end up creating incredibly difficult to figure out bugs.The
setValues
function can allocate these using reflect.Note that all this per-row allocation is going to cost a little something, so if speed is a priority I recommend against pointer embeds.
The text was updated successfully, but these errors were encountered: