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

Function ExampleRowTo

rows_test.go:345–366  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

343}
344
345func 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
368func TestRowToAddrOf(t *testing.T) {
369 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