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
So, I misunderstood the API of Select, and didn't realize it was always expecting a slice... and so I passed it a pointer to a struct, figuring it would realize it was a struct and just do one row.... I got back a really ugly panic:
There seem to be a couple ways to handle this with better results:
1.) Allow this to work, just check to see if the thing passed in is a struct, and if so, just scan the first returned row
2.) Don't allow it to work, but handle the error with a more friendly error message
for #2, it might also be beneficial to rename the parameter as something like dest_slice ... to make it a little more obvious that it requires a slice.
The text was updated successfully, but these errors were encountered:
This should definitely not panic but return a proper err instead. There is already dbx.Get() which is the QueryRow of Select's Query, so doubling that behavior in Select will probably be more of a bug than a feature for most people.
So, I misunderstood the API of Select, and didn't realize it was always expecting a slice... and so I passed it a pointer to a struct, figuring it would realize it was a struct and just do one row.... I got back a really ugly panic:
reflect.(_rtype).Elem(...)
/home/nate/go/src/pkg/reflect/type.go:584 +0x118
github.com/jmoiron/sqlx.StructScan(...)
/home/nate/code/go/src/github.com/jmoiron/sqlx/sqlx.go:761 +0x1b4
github.com/jmoiron/sqlx.Select(...)
/home/nate/code/go/src/github.com/jmoiron/sqlx/sqlx.go:508 +0xbe
github.com/jmoiron/sqlx.(_DB).Select(...)
/home/nate/code/go/src/github.com/jmoiron/sqlx/sqlx.go:160 +0x71
There seem to be a couple ways to handle this with better results:
1.) Allow this to work, just check to see if the thing passed in is a struct, and if so, just scan the first returned row
2.) Don't allow it to work, but handle the error with a more friendly error message
for #2, it might also be beneficial to rename the parameter as something like dest_slice ... to make it a little more obvious that it requires a slice.
The text was updated successfully, but these errors were encountered: