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

Function ExampleRowToAddrOf

rows_test.go:381–408  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

379}
380
381func 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
410func TestRowToMap(t *testing.T) {
411 defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {

Callers

nothing calls this directly

Calls 2

QueryMethod · 0.65
ConnectMethod · 0.45

Tested by

no test coverage detected