pgx

package
v1.72.0-dev Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 20, 2025 License: Apache-2.0, BSD-3-Clause, Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	AcquireCount            = tracerPrefix + "pgx.pool.connections.acquire"
	AcquireDuration         = tracerPrefix + "pgx.pool.connections.acquire_duration"
	AcquiredConns           = tracerPrefix + "pgx.pool.connections.acquired_conns"
	CanceledAcquireCount    = tracerPrefix + "pgx.pool.connections.canceled_acquire"
	ConstructingConns       = tracerPrefix + "pgx.pool.connections.constructing_conns"
	EmptyAcquireCount       = tracerPrefix + "pgx.pool.connections.empty_acquire"
	IdleConns               = tracerPrefix + "pgx.pool.connections.idle_conns"
	MaxConns                = tracerPrefix + "pgx.pool.connections.max_conns"
	TotalConns              = tracerPrefix + "pgx.pool.connections.total_conns"
	NewConnsCount           = tracerPrefix + "pgx.pool.connections.new_conns"
	MaxLifetimeDestroyCount = tracerPrefix + "pgx.pool.connections.max_lifetime_destroy"
	MaxIdleDestroyCount     = tracerPrefix + "pgx.pool.connections.max_idle_destroy"
)

Variables

This section is empty.

Functions

func Connect

func Connect(ctx context.Context, connString string, opts ...Option) (*pgx.Conn, error)

Connect is equivalent to pgx.Connect providing a connection augmented with tracing.

Example
Output:

func ConnectConfig

func ConnectConfig(ctx context.Context, connConfig *pgx.ConnConfig, opts ...Option) (*pgx.Conn, error)

ConnectConfig is equivalent to pgx.ConnectConfig providing a connection augmented with tracing.

func ConnectWithOptions added in v1.69.1

func ConnectWithOptions(ctx context.Context, connString string, options pgx.ParseConfigOptions, tracerOpts ...Option) (*pgx.Conn, error)

ConnectWithOptions is equivalent to pgx.ConnectWithOptions providing a connection augmented with tracing.

func NewPool

func NewPool(ctx context.Context, connString string, opts ...Option) (*pgxpool.Pool, error)
Example
Output:

func NewPoolWithConfig

func NewPoolWithConfig(ctx context.Context, config *pgxpool.Config, opts ...Option) (*pgxpool.Pool, error)

Types

type Batch deprecated

type Batch = pgx.Batch

Deprecated: this type is unused internally so it will be removed in a future release, please use pgx.Batch instead.

type Option

type Option func(*config)

func WithPoolStats added in v1.67.0

func WithPoolStats() Option

WithPoolStats enables polling of pgxpool.Stat metrics ref: https://pkg.go.dev/github.com/jackc/pgx/v5/pgxpool#Stat These metrics are submitted to Datadog and are not billed as custom metrics

func WithServiceName

func WithServiceName(name string) Option

WithServiceName sets the service name to use for all spans.

func WithTraceAcquire added in v1.67.0

func WithTraceAcquire(enabled bool) Option

WithTraceAcquire enables tracing pgxpool connection acquire calls.

func WithTraceBatch

func WithTraceBatch(enabled bool) Option

WithTraceBatch enables tracing batched operations (i.e. pgx.Batch{}).

func WithTraceConnect

func WithTraceConnect(enabled bool) Option

WithTraceConnect enables tracing calls to Connect and ConnectConfig.

pgx.Connect(ctx, "postgres://user:pass@example.com:5432/dbname", pgx.WithTraceConnect())

func WithTraceCopyFrom

func WithTraceCopyFrom(enabled bool) Option

WithTraceCopyFrom enables tracing pgx.CopyFrom calls.

func WithTracePrepare

func WithTracePrepare(enabled bool) Option

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

func WithTraceQuery(enabled bool) Option

WithTraceQuery enables tracing query operations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL