Documentation
¶
Index ¶
- Constants
- func AcquireAdvisoryLock(ctx context.Context, q Querier, lockKey int) (bool, error)
- func Migrate(ctx context.Context, databaseURL string, direction migrate.MigrationDirection, ...) (int, error)
- func OpenDBConnectionPool(ctx context.Context, dataSourceName string, poolConfigs ...PoolConfig) (*pgxpool.Pool, error)
- func QueryMany[T any](ctx context.Context, q Querier, query string, args ...any) ([]T, error)
- func QueryManyPtrs[T any](ctx context.Context, q Querier, query string, args ...any) ([]*T, error)
- func QueryOne[T any](ctx context.Context, q Querier, query string, args ...any) (T, error)
- func ReleaseAdvisoryLock(ctx context.Context, q Querier, lockKey int) error
- func RunInReadSnapshot(ctx context.Context, pool *pgxpool.Pool, fn func(ctx context.Context) error) error
- func RunInTransaction(ctx context.Context, beginner TxBeginner, fn func(pgx.Tx) error) error
- func RunProtocolMigrations(ctx context.Context, dbPool *pgxpool.Pool) (int, error)
- func SQLDBFromPool(pool *pgxpool.Pool) *sql.DB
- type PoolConfig
- type Querier
- type TxBeginner
Constants ¶
const ( DefaultMaxConnIdleTime time.Duration = 10 * time.Second // MinIngestMaxConns is the smallest pool live persist can run in: 6 connections // held at its commit barrier (the coordinator plus 5 siblings), plus the // advisory-lock session, which is held until the process exits. Below this, a // sibling waits forever for a connection nothing releases. MinIngestMaxConns int32 = 7 // DefaultMaxConns leaves headroom for the transient classification reads. DefaultMaxConns int32 = 12 DefaultMinConns int32 = 5 DefaultMaxConnLifetime time.Duration = 5 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
func AcquireAdvisoryLock ¶
AcquireAdvisoryLock attempt to acquire an advisory lock on the provided lockKey, returns true if acquired, or false not.
func OpenDBConnectionPool ¶
func QueryMany ¶
QueryMany executes a query and scans all result rows into []T. For struct types, it uses pgx named-field scanning (db tags). For scalar types (int, bool, string, etc.), it uses direct column scanning. Returns an empty slice (not nil) if no rows are found.
func QueryManyPtrs ¶
QueryManyPtrs executes a query and scans all result rows into []*T. For struct types, it uses pgx named-field scanning (db tags). For scalar types (int, bool, string, etc.), it uses direct column scanning. Returns an empty slice (not nil) if no rows are found.
func QueryOne ¶
QueryOne executes a query and scans the single result row into T. For struct types, it uses pgx named-field scanning (db tags). For scalar types (int, bool, string, etc.), it uses direct column scanning. Returns pgx.ErrNoRows if no row is found.
func ReleaseAdvisoryLock ¶
ReleaseAdvisoryLock releases an advisory lock on the provided lockKey.
func RunInReadSnapshot ¶
func RunInReadSnapshot(ctx context.Context, pool *pgxpool.Pool, fn func(ctx context.Context) error) error
RunInReadSnapshot runs fn with a context whose reads (through QuerierFrom) share one read-only REPEATABLE READ transaction, so every query in fn sees the same committed state. fn must query from one goroutine at a time: a pgx.Tx is not safe for concurrent use.
func RunInTransaction ¶
RunInTransaction runs the given atomic function in a pgx transaction. It automatically rolls back on error and commits on success.
func RunProtocolMigrations ¶
RunProtocolMigrations executes all embedded protocol SQL files to register protocols in the database. Protocol SQL files are idempotent.
Types ¶
type PoolConfig ¶
type PoolConfig struct {
MaxConns int32
MinConns int32
MaxConnLifetime time.Duration
MaxConnIdleTime time.Duration
QueryExecMode pgx.QueryExecMode // 0 = pgx default (CacheStatement)
}
PoolConfig holds configurable pgxpool settings. Zero values fall back to Default* constants.
func DefaultPoolConfig ¶
func DefaultPoolConfig() PoolConfig
DefaultPoolConfig returns a PoolConfig populated with the default values.
type Querier ¶
type Querier interface {
Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
}
Querier is the minimal interface shared by *pgxpool.Pool and pgx.Tx. It allows QueryOne/QueryMany to work with both pool and transaction.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package dbtest provides test database utilities with TimescaleDB support.
|
Package dbtest provides test database utilities with TimescaleDB support. |