| 176 | } |
| 177 | |
| 178 | func 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. |