MCPcopy
hub / github.com/jackc/pgx / TestCollectRowsEmpty

Function TestCollectRowsEmpty

rows_test.go:178–191  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

176}
177
178func TestCollectRowsEmpty(t *testing.T) {
179 defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
180 rows, _ := conn.Query(ctx, `select n from generate_series(1, 0) n`)
181 numbers, err := pgx.CollectRows(rows, func(row pgx.CollectableRow) (int32, error) {
182 var n int32
183 err := row.Scan(&n)
184 return n, err
185 })
186 require.NoError(t, err)
187 require.NotNil(t, numbers)
188
189 assert.Empty(t, numbers)
190 })
191}
192
193// This example uses CollectRows with a manually written collector function. In most cases RowTo, RowToAddrOf,
194// RowToStructByPos, RowToAddrOfStructByPos, or another generic function would be used.

Callers

nothing calls this directly

Calls 3

RunTestMethod · 0.80
QueryMethod · 0.65
ScanMethod · 0.65

Tested by

no test coverage detected