Documentation ¶
Index ¶
- func Connect(ctx context.Context, connString string, opts ...Option) (*pgx.Conn, error)
- func ConnectConfig(ctx context.Context, connConfig *pgx.ConnConfig, opts ...Option) (*pgx.Conn, error)
- func NewPool(ctx context.Context, connString string, opts ...Option) (*pgxpool.Pool, error)
- func NewPoolWithConfig(ctx context.Context, config *pgxpool.Config, opts ...Option) (*pgxpool.Pool, error)
- type Batch
- type Option
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Connect ¶
Example ¶
ctx := context.TODO() // The package exposes the same connect functions as the regular pgx.v5 library // which sets up a tracer and connects as usual. db, err := pgxtrace.Connect(ctx, "postgres://pqgotest:password@localhost/pqgotest?sslmode=disable") if err != nil { log.Fatal(err) } defer db.Close(ctx) // Any calls made to the database will be traced as expected. rows, err := db.Query(ctx, "SELECT name FROM users WHERE age=$1", 27) if err != nil { log.Fatal(err) } defer rows.Close() // This enables you to use PostgresSQL specific functions implemented by pgx.v5. numbers := []int{1, 2, 3} copyFromSource := pgx.CopyFromSlice(len(numbers), func(i int) ([]any, error) { return []any{numbers[i]}, nil }) _, err = db.CopyFrom(ctx, []string{"numbers"}, []string{"number"}, copyFromSource) if err != nil { log.Fatal(err) }
Output:
func ConnectConfig ¶
Types ¶
type Option ¶
type Option func(*config)
func WithServiceName ¶
WithServiceName sets the service name to use for all spans.
func WithTraceBatch ¶
WithTraceBatch enables tracing batched operations (i.e. pgx.Batch{}).
func WithTraceConnect ¶
WithTraceConnect enables tracing calls to Connect and ConnectConfig.
pgx.Connect(ctx, "postgres://user:pass@example.com:5432/dbname", pgx.WithTraceConnect())
func WithTraceCopyFrom ¶
WithTraceCopyFrom enables tracing pgx.CopyFrom calls.
func WithTracePrepare ¶
WithTracePrepare enables tracing prepared statements.
conn, err := pgx.Connect(ctx, "postgres://user:pass@example.com:5432/dbname", pgx.WithTraceConnect()) if err != nil { // handle err } defer conn.Close(ctx) _, err := conn.Prepare(ctx, "stmt", "select $1::integer") row, err := conn.QueryRow(ctx, "stmt", 1)
func WithTraceQuery ¶
WithTraceQuery enables tracing query operations.
Click to show internal directories.
Click to hide internal directories.