-
Release v0.9.0 Stable
released this
2026-03-19 07:18:59 -06:00 | 0 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