Fix scan array of record to pointer to slice of struct
https://github.com/jackc/pgx/issues/1570
This commit is contained in:
@@ -330,6 +330,22 @@ func TestMapScanPtrToPtrToSlice(t *testing.T) {
|
||||
require.Equal(t, []string{"foo", "bar"}, *v)
|
||||
}
|
||||
|
||||
func TestMapScanPtrToPtrToSliceOfStruct(t *testing.T) {
|
||||
type Team struct {
|
||||
TeamID int
|
||||
Name string
|
||||
}
|
||||
|
||||
// Have to use binary format because text format doesn't include type information.
|
||||
m := pgtype.NewMap()
|
||||
src := []byte{0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x8, 0xc9, 0x0, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1e, 0x0, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x17, 0x0, 0x0, 0x0, 0x4, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x19, 0x0, 0x0, 0x0, 0x6, 0x74, 0x65, 0x61, 0x6d, 0x20, 0x31, 0x0, 0x0, 0x0, 0x1e, 0x0, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x17, 0x0, 0x0, 0x0, 0x4, 0x0, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x19, 0x0, 0x0, 0x0, 0x6, 0x74, 0x65, 0x61, 0x6d, 0x20, 0x32}
|
||||
var v *[]Team
|
||||
plan := m.PlanScan(pgtype.RecordArrayOID, pgtype.BinaryFormatCode, &v)
|
||||
err := plan.Scan(src, &v)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, []Team{{1, "team 1"}, {2, "team 2"}}, *v)
|
||||
}
|
||||
|
||||
type databaseValuerString string
|
||||
|
||||
func (s databaseValuerString) Value() (driver.Value, error) {
|
||||
|
||||
Reference in New Issue
Block a user