| 379 | } |
| 380 | |
| 381 | func ExampleRowToAddrOf() { |
| 382 | ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second) |
| 383 | defer cancel() |
| 384 | |
| 385 | conn, err := pgx.Connect(ctx, os.Getenv("PGX_TEST_DATABASE")) |
| 386 | if err != nil { |
| 387 | fmt.Printf("Unable to establish connection: %v", err) |
| 388 | return |
| 389 | } |
| 390 | |
| 391 | rows, _ := conn.Query(ctx, `select n from generate_series(1, 5) n`) |
| 392 | pNumbers, err := pgx.CollectRows(rows, pgx.RowToAddrOf[int32]) |
| 393 | if err != nil { |
| 394 | fmt.Printf("CollectRows error: %v", err) |
| 395 | return |
| 396 | } |
| 397 | |
| 398 | for _, p := range pNumbers { |
| 399 | fmt.Println(*p) |
| 400 | } |
| 401 | |
| 402 | // Output: |
| 403 | // 1 |
| 404 | // 2 |
| 405 | // 3 |
| 406 | // 4 |
| 407 | // 5 |
| 408 | } |
| 409 | |
| 410 | func TestRowToMap(t *testing.T) { |
| 411 | defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { |