2
0

Add RowScanner interface

This commit is contained in:
Jack Christensen
2022-04-30 12:49:12 -05:00
parent 01190e5d78
commit c1495aace0
3 changed files with 47 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
package pgx_test
import (
"context"
"testing"
"github.com/jackc/pgx/v5"
"github.com/stretchr/testify/require"
)
type testRowScanner struct {
name string
age int32
}
func (rs *testRowScanner) ScanRow(rows pgx.Rows) error {
return rows.Scan(&rs.name, &rs.age)
}
func TestRowScanner(t *testing.T) {
t.Parallel()
defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
var s testRowScanner
err := conn.QueryRow(ctx, "select 'Adam' as name, 72 as height").Scan(&s)
require.NoError(t, err)
require.Equal(t, "Adam", s.name)
require.Equal(t, int32(72), s.age)
})
}