Rene Nochebuena 4d6d2f1d62 feat(postgres)!: promote to v1.0.0 — BeginTx with pgx options, Stats, bump all deps to v1.0.0
Add BeginTx(ctx, pgx.TxOptions) to Client interface for explicit isolation level and
read-only transaction control; Begin refactored as a convenience wrapper calling
BeginTx(ctx, pgx.TxOptions{}). Add Stats() *pgxpool.Stat to Component interface for
connection pool observability. Bump all micro-lib dependencies (logz, health, launcher,
xerrors) from v0.9.0 to v1.0.0. API committed as stable.
2026-05-11 19:36:47 -06:00

postgres

pgx-backed PostgreSQL client with launcher lifecycle and health check integration.

Install

go get code.nochebuena.dev/go/postgres

Usage

db := postgres.New(logger, cfg)
lc.Append(db)
r.Get("/health", health.NewHandler(logger, db))

Querying

exec := db.GetExecutor(ctx) // returns pool, or active Tx if inside Do()

rows, err := exec.Query(ctx, "SELECT id, name FROM users WHERE active = $1", true)
defer rows.Close()

Unit of Work

uow := postgres.NewUnitOfWork(logger, db)

err := uow.Do(ctx, func(ctx context.Context) error {
    exec := db.GetExecutor(ctx) // returns the transaction
    _, err := exec.Exec(ctx, "INSERT INTO orders ...")
    return err
})

Error mapping

if err := db.HandleError(err); err != nil { ... }
// or package-level: postgres.HandleError(err)
PostgreSQL error xerrors code
unique_violation ErrAlreadyExists
foreign_key_violation ErrInvalidInput
check_violation ErrInvalidInput
pgx.ErrNoRows ErrNotFound
anything else ErrInternal

Configuration

Env var Default Description
PG_HOST required Database host
PG_PORT 5432 Database port
PG_USER required Username
PG_PASSWORD required Password
PG_NAME required Database name
PG_SSL_MODE disable SSL mode
PG_MAX_CONNS 5 Max pool connections
PG_MIN_CONNS 2 Min pool connections
Description
PostgreSQL client with health check and lifecycle hooks.
Readme MIT 58 KiB
2026-05-11 19:37:43 -06:00
Languages
Go 100%