-
Release v1.0.0 Stable
released this
2026-05-11 19:37:43 -06:00 | 1 commits to main since this releasev1.0.0
code.nochebuena.dev/go/postgresOverview
postgresv1.0.0 commits the database client API as stable. All v0.9.0 roadmap items are
resolved. The module ships a pgx v5-native PostgreSQL client that integrates with thelauncher
lifecycle andhealthcheck systems, maps PostgreSQL errors to portablexerrorscodes, and
providesUnitOfWorkfor transactional repository patterns via context injection.What Changed Since v0.9.0
New in Client interface
BeginTx(ctx context.Context, opts pgx.TxOptions) (Tx, error)— starts a transaction with
explicit isolation level and read-only options using pgx-nativepgx.TxOptions.Begin(ctx)
is now a convenience wrapper callingBeginTx(ctx, pgx.TxOptions{}).tx, err := db.BeginTx(ctx, pgx.TxOptions{ IsoLevel: pgx.Serializable, AccessMode: pgx.ReadWrite, })New in Component interface
Stats() *pgxpool.Stat— exposes connection pool metrics for observability. Returns a
zero-value*pgxpool.Statwhen called beforeOnInit. Useful for Prometheus gauges or
health dashboards:stats := db.Stats() // stats.TotalConns(), stats.IdleConns(), stats.AcquiredConns(), stats.MaxConns()Dependency bumps
All micro-lib dependencies promoted to v1.0.0:
logz,health,launcher,xerrors.Roadmap items resolved
Item Resolution BeginTx(ctx, opts)for serialisable isolation✅ Added to Clientwithpgx.TxOptions;Beginrefactored as wrapperStats()for pool observability✅ Added Stats() *pgxpool.StattoComponentSELECT 1health check option❌ No — pgxpool.Pingalready acquires a real connection and does a round-trip; SELECT 1 adds no additional signalProduction feedback on pool defaults ✅ Validated as-is — MaxConns=5,MinConns=2,1h/30m/1mconfirmed in productionFull API (stable)
Executor—Exec,Query,QueryRowusing pgx v5 native types (pgconn.CommandTag,pgx.Rows,pgx.Row).Tx— extendsExecutorwithCommit(ctx) error,Rollback(ctx) error.Client—GetExecutor(ctx) Executor,Begin(ctx) (Tx, error),BeginTx(ctx, pgx.TxOptions) (Tx, error),Ping(ctx) error,HandleError(err) error.Component—launcher.Component+health.Checkable+Client+Stats() *pgxpool.Stat.UnitOfWork—Do(ctx, fn) error; injects activepgx.Txvia context.Config—Host,Port,User,Password,Name,SSLMode,Timezone,MaxConns,MinConns,MaxConnLifetime,MaxConnIdleTime,HealthCheckPeriod; env-tag support.New(logger logz.Logger, cfg Config) Component— constructor; pool created inOnInit.NewUnitOfWork(logger logz.Logger, client Client) UnitOfWork— wraps aClientfor transactionalDosemantics.HandleError(err error) error— maps pgx/PostgreSQL errors to xerrors:UniqueViolation→ErrAlreadyExists;ForeignKeyViolation/CheckViolation→ErrInvalidInput;pgx.ErrNoRows→ErrNotFound; others →ErrInternal.Migration from v0.9.0
BeginTxis a new method onClient. Any type that implementsClientmust now also
implementBeginTx. The existingBeginbehavior is unchanged.Statsis a new method onComponent. Any type that implementsComponentmust now also
implementStats.go get code.nochebuena.dev/go/postgres@v1.0.0Downloads
-
Release v0.9.0 Stable
released this
2026-03-19 07:18:59 -06:00 | 2 commits to main since this releasev0.9.0
code.nochebuena.dev/go/postgresOverview
postgresis a pgx v5-native PostgreSQL client that integrates with thelauncherlifecycle
andhealthcheck systems. It manages apgxpoolconnection pool, maps PostgreSQL errors to
portablexerrorscodes, and provides aUnitOfWorkimplementation that injects the active
transaction into the context so repositories participate in transactions without explicit wiring.This is the first stable release. The API was designed through multiple architecture reviews
and validated end-to-end via the todo-api proof-of-concept. It is versioned at v0.9.0 rather
than v1.0.0 because the library has not yet been exercised in production across all edge cases;
the pre-1.0 version preserves the option for minor API refinements without a major bump.What's Included
Executorinterface:Exec,Query,QueryRowusing pgx v5 native types
(pgconn.CommandTag,pgx.Rows,pgx.Row)Txinterface: extendsExecutorwithCommit(ctx)/Rollback(ctx)Clientinterface:GetExecutor(ctx),Begin(ctx),Ping(ctx),HandleError(err)Componentinterface: composeslauncher.Component,health.Checkable, andClientNew(logger, cfg) Componentconstructor; pool initialised inOnInit, not at constructionConfigstruct with env-tag support (PG_HOST,PG_PORT,PG_USER,PG_PASSWORD,
PG_NAME,PG_SSL_MODE,PG_MAX_CONNS,PG_MIN_CONNS, connection lifetime fields)UnitOfWorkinterface andNewUnitOfWork(logger, client)constructor using context injectionHandleError(err) errorpackage-level function mapping pgx/PostgreSQL errors to xerrors:UniqueViolation→ErrAlreadyExistswith constraint name contextForeignKeyViolation→ErrInvalidInputwith table name contextCheckViolation→ErrInvalidInputwith table and column contextpgx.ErrNoRows→ErrNotFound- all other errors →
ErrInternal
health.Checkableimplementation athealth.LevelCritical
Installation
go get code.nochebuena.dev/go/postgres@v0.9.0Requires Go 1.21 or later. Depends on
code.nochebuena.dev/go/health,
code.nochebuena.dev/go/launcher,code.nochebuena.dev/go/logz,
code.nochebuena.dev/go/xerrors, andgithub.com/jackc/pgx/v5.Design Highlights
pgx native types throughout.
Executorusespgconn.CommandTag,pgx.Rows, and
pgx.Rowdirectly. There is nodatabase/sqladapter; this is an intentional design choice
to give repository code access to pgx-specific features (named parameters, pgtype, etc.).No dbutil wrapper.
Executor,Tx,Client, andComponentare defined locally in
this package using pgx types. Themysqlmodule has its own independentExecutor. The two
are intentionally incompatible.UnitOfWork via context injection.
NewUnitOfWork.Dobegins a transaction, stores it in
the context under an unexported key, and calls the provided function.GetExecutor(ctx)returns
the transaction when one is present, otherwise the pool. Repositories need no awareness of
whether they are inside a transaction.Error mapping by pgerrcode constants.
HandleErroruseserrors.Asto unwrap
*pgconn.PgErrorand switches onpgerrcodeconstants, not message strings.Lifecycle-aware health check.
HealthCheckdelegates toPing, which calls
pgxpool.Pool.Ping. Priority ishealth.LevelCritical.Known Limitations & Edge Cases
- No query builder. Repository code writes raw SQL strings. There is no DSL or prepared
statement cache beyond what pgxpool provides natively. - No migration helper. Schema migrations are out of scope; use a dedicated tool such as
golang-migrateorgoose. - Health check uses pgxpool.Ping, not
SELECT 1.Pool.Pingacquires a connection from
the pool and calls the pgx-level ping. It does not execute a query, so it may not detect all
forms of server-side unavailability. - Transaction stored in context is not safe to use after
Doreturns. Goroutines launched
insideUnitOfWork.Dothat outlive the callback will hold a reference to a committed or
rolled-back transaction.
v0.9.0 → v1.0.0 Roadmap
- Evaluate adding a
SELECT 1health check option alongside the pool ping. - Consider exposing connection pool stats (idle, total, wait count) through the health check
or a dedicated metrics hook. - Assess whether a
BeginTx(ctx, opts)variant is needed for serialisable isolation. - Gather production feedback on connection pool defaults before hardening the config.
Downloads