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 RunInTransaction(ctx context.Context, pool *pgxpool.Pool, fn func(pgx.Tx) error) error
- func SQLDBFromPool(pool *pgxpool.Pool) *sql.DB
- type PoolConfig
- type Querier
Constants ¶
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 RunInTransaction ¶
RunInTransaction runs the given atomic function in a pgx transaction. It automatically rolls back on error and commits on success.
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. |