pgtool

package
v19.0.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpenPool

OpenPool opens a pgxpool.Pool from cfg with otelpgx tracing and stats wiring. name is applied as a `pool` attribute to all stats metrics so multiple pools pointing at the same host:port/database can be distinguished in metrics backends. opts may override fields on the parsed pgxpool.Config (e.g. MaxConns/MinConns).

func Query

func Query[T any](ctx context.Context, tx Querier, query string, scanRow func(pgx.Rows) (T, error), args ...any) ([]T, error)

func RunMigrations

func RunMigrations(ctx context.Context, log *slog.Logger, cfg DBConnConfig, name string, migrationsFS fs.FS) error

RunMigrations applies pending migrations from migrationsFS using goose. The DSN must bypass PgBouncer because goose relies on session-level pg_advisory_lock for cross-replica coordination. name scopes goose's tracking table and advisory lock so multiple modules can share the same database without colliding.

Types

type DBConnConfig

type DBConnConfig struct {
	DSN       string
	TLSConfig *tls.Config
}

DBConnConfig is the configuration for opening a single pool or running migrations.

type PoolOption

type PoolOption func(*pgxpool.Config)

PoolOption overrides fields on the pgxpool.Config parsed from the DSN before the pool is opened.

func WithMaxConns

func WithMaxConns(n int32) PoolOption

WithMaxConns overrides the pool's MaxConns.

func WithMinConns

func WithMinConns(n int32) PoolOption

WithMinConns overrides the pool's MinConns.

type Querier

type Querier interface {
	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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