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.
4.0 KiB
4.0 KiB
Changelog
All notable changes to this module will be documented in this file.
The format is based on Keep a Changelog, and this module adheres to Semantic Versioning.
1.0.0 — 2026-05-12
Added
Client.BeginTx(ctx context.Context, opts pgx.TxOptions) (Tx, error)— starts a transaction with explicit isolation level and read-only options using pgx-nativepgx.TxOptions.Component.Stats() *pgxpool.Stat— returns connection pool metrics (TotalConns,IdleConns,AcquiredConns,MaxConns, etc.) for observability and alerting; returns a zero-value*pgxpool.Statwhen called beforeOnInit.
Changed
Client.Begin(ctx context.Context) (Tx, error)— refactored as a convenience wrapper callingBeginTx(ctx, pgx.TxOptions{}); behavior is identical, no breaking change.- All micro-lib dependencies bumped from v0.9.0 to v1.0.0:
logz,health,launcher,xerrors.
Unchanged
All other API (Executor, Tx, Client, Component, UnitOfWork, Config, New,
NewUnitOfWork, HandleError) is API-compatible with v0.9.0.
0.9.0 - 2026-03-18
Added
Executorinterface:Exec,Query,QueryRowusing native pgx types (pgconn.CommandTag,pgx.Rows,pgx.Row).Txinterface: embedsExecutorand addsCommit(ctx context.Context) errorandRollback(ctx context.Context) error.Clientinterface:GetExecutor(ctx context.Context) Executor,Begin(ctx context.Context) (Tx, error),Ping(ctx context.Context) error,HandleError(err error) error.Componentinterface: composeslauncher.Component,health.Checkable, andClientinto a single injectable dependency.UnitOfWorkinterface:Do(ctx context.Context, fn func(ctx context.Context) error) error.Configstruct: fieldsHost,Port,User,Password,Name,SSLMode,Timezone,MaxConns,MinConns,MaxConnLifetime,MaxConnIdleTime,HealthCheckPeriod; all settable via environment variables withenvstruct tags and sensible defaults.Config.DSN() string: constructs apostgres://URL including SSL mode and timezone query parameters.New(logger logz.Logger, cfg Config) Component: returns apgxpool-backed component; pool is created lazily inOnInit.- Lifecycle hooks:
OnInitparses config and creates the connection pool with a 30-second timeout;OnStartpings the database with a 5-second timeout;OnStopcloses the pool gracefully. health.Checkableimplementation:HealthCheckdelegates toPing;Name()returns"postgres";Priority()returnshealth.LevelCritical.NewUnitOfWork(logger logz.Logger, client Client) UnitOfWork: wraps aClientto provide transactionalDosemantics; rolls back and logs on error, commits on success.HandleError(err error) error(package-level function): maps*pgconn.PgErrorcodes to xerrors —UniqueViolation→ErrAlreadyExists,ForeignKeyViolation→ErrInvalidInput,CheckViolation→ErrInvalidInput;pgx.ErrNoRows→ErrNotFound; all other errors →ErrInternal.- Transaction context injection: the active
pgx.Txis stored under an unexportedctxTxKey{}context key;GetExecutorreturns the transaction when found, otherwise returns the pool. - All pool reads guarded by
sync.RWMutexfor safe concurrent access.
Design Notes
- All interfaces use pgx-native types (
pgconn.CommandTag,pgx.Rows,pgx.Row) directly; there is nodatabase/sqladapter. This is intentional and incompatible with themysqlmodule by design. UnitOfWork.Doinjects the transaction into the context so repositories can callGetExecutor(ctx)transparently without knowing whether a transaction is active.- PostgreSQL error codes are matched via
pgerrcodeconstants anderrors.As, never by parsing error message strings.