RowTo(AddrOf)StructByPos ignores fields with "-" db tag
https://github.com/jackc/pgx/discussions/1682
This commit is contained in:
@@ -384,6 +384,24 @@ func TestRowToStructByPos(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestRowToStructByPosIgnoredField(t *testing.T) {
|
||||
type person struct {
|
||||
Name string
|
||||
Age int32 `db:"-"`
|
||||
}
|
||||
|
||||
defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||
rows, _ := conn.Query(ctx, `select 'Joe' as name from generate_series(0, 9) n`)
|
||||
slice, err := pgx.CollectRows(rows, pgx.RowToStructByPos[person])
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Len(t, slice, 10)
|
||||
for i := range slice {
|
||||
assert.Equal(t, "Joe", slice[i].Name)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestRowToStructByPosEmbeddedStruct(t *testing.T) {
|
||||
type Name struct {
|
||||
First string
|
||||
|
||||
Reference in New Issue
Block a user