| 343 | } |
| 344 | |
| 345 | func ExampleRowTo() { |
| 346 | ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second) |
| 347 | defer cancel() |
| 348 | |
| 349 | conn, err := pgx.Connect(ctx, os.Getenv("PGX_TEST_DATABASE")) |
| 350 | if err != nil { |
| 351 | fmt.Printf("Unable to establish connection: %v", err) |
| 352 | return |
| 353 | } |
| 354 | |
| 355 | rows, _ := conn.Query(ctx, `select n from generate_series(1, 5) n`) |
| 356 | numbers, err := pgx.CollectRows(rows, pgx.RowTo[int32]) |
| 357 | if err != nil { |
| 358 | fmt.Printf("CollectRows error: %v", err) |
| 359 | return |
| 360 | } |
| 361 | |
| 362 | fmt.Println(numbers) |
| 363 | |
| 364 | // Output: |
| 365 | // [1 2 3 4 5] |
| 366 | } |
| 367 | |
| 368 | func TestRowToAddrOf(t *testing.T) { |
| 369 | defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { |