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
The database/sql approach of using PG parameters works fine, but using sqlx's NamedQuery results in a panic.
I believe that the issue is stemming from the fact sqlx.getFieldMap maps the fields in the embedded struct T to indexes as follows:
map[string]int{
"id": 0,
"field": 1,
}
, while the application of that mapping, via reflect.ValueOf(arg), where arg is the Container struct c, results in the first index of the map (which should map to c.T.Id) actually mapping to c.T. From there it's straightforward to see that there is no field available at the index 1 in the struct.
So, it appears that the implementation in sqlx.BindStruct does not make the right calls to the reflect package to get fields in the embedded field T, but instead gets the field(s) in the Container struct.
The text was updated successfully, but these errors were encountered:
I spoke to @jmoiron briefly about this on Friday, and have put together a simple example to show problem.
When using NamedQuery with an embedded struct, Go panics:
Reproduce Issue
I can reproduce the issue by creating a PostgreSQL table according to the following schema:
And then using the following Go program:
The
database/sql
approach of using PG parameters works fine, but using sqlx'sNamedQuery
results in a panic.I believe that the issue is stemming from the fact
sqlx.getFieldMap
maps the fields in the embedded structT
to indexes as follows:, while the application of that mapping, via
reflect.ValueOf(arg)
, wherearg
is theContainer
structc
, results in the first index of the map (which should map toc.T.Id
) actually mapping toc.T
. From there it's straightforward to see that there is no field available at the index 1 in the struct.So, it appears that the implementation in
sqlx.BindStruct
does not make the right calls to thereflect
package to get fields in the embedded fieldT
, but instead gets the field(s) in theContainer
struct.The text was updated successfully, but these errors were encountered: