2
0

RowTo(AddrOf)StructByPos ignores fields with "-" db tag

https://github.com/jackc/pgx/discussions/1682
This commit is contained in:
Jack Christensen
2023-07-15 09:39:20 -05:00
parent 038fc448c1
commit 2f6fcf8eb0
2 changed files with 27 additions and 2 deletions
+18
View File
@@ -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