All v0.9.0 roadmap items evaluated in production. WAL + write-mutex serialisation validated under real workloads; no API changes needed. Read/write pool separation and Pragmas structured type deferred as out-of-scope for this use case tier. Bump all micro-lib dependencies (logz, health, launcher, xerrors) from v0.9.0 to v1.0.0. API committed as stable.
3.6 KiB
3.6 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
Changed
- All micro-lib dependencies bumped from v0.9.0 to v1.0.0:
logz,health,launcher,xerrors.
Unchanged
All existing 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:ExecContext,QueryContext,QueryRowContextusingdatabase/sqltypes (sql.Result,*sql.Rows,*sql.Row).Txinterface: embedsExecutorand addsCommit() errorandRollback() error(no context argument, matchingdatabase/sqlsemantics).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, andClient.UnitOfWorkinterface:Do(ctx context.Context, fn func(ctx context.Context) error) error.Configstruct: fieldsPath(SQLITE_PATH),MaxOpenConns(default1),MaxIdleConns(default1),Pragmas(default?_journal=WAL&_timeout=5000&_fk=true); settable viaSQLITE_*environment variables.New(logger logz.Logger, cfg Config) Component: returns a pure-Go SQLite component backed bymodernc.org/sqlite; no CGO required.- Lifecycle hooks:
OnInitopens the database, sets connection limits, and enforcesPRAGMA foreign_keys = ON; startup fails if the pragma cannot be set.OnStartpings with a 5-second timeout.OnStopcloses the connection. health.Checkableimplementation:HealthCheckdelegates toPing;Name()returns"sqlite";Priority()returnshealth.LevelCritical.NewUnitOfWork(logger logz.Logger, client Client) UnitOfWork: wraps aClientto provide transactionalDosemantics. When the client is the concrete*sqliteComponent, the write mutex is acquired for the duration ofDoto serialise concurrent write transactions and preventSQLITE_BUSY.HandleError(err error) error(package-level function): maps SQLite extended error codes via a duck-typedcoderinterface — code2067(unique constraint) and1555(primary key constraint) →ErrAlreadyExists; code787(foreign key constraint) →ErrInvalidInput;sql.ErrNoRows→ErrNotFound; all others →ErrInternal.- Transaction context injection: the active
*sql.Txis stored under an unexportedctxTxKey{}context key;GetExecutorreturns it when found, otherwise returns*sql.DB. - WAL journal mode, 5-second busy timeout, and foreign key enforcement enabled by default via the
PragmasDSN suffix. - Support for in-memory databases via
Config{Path: ":memory:"}for test isolation.
Design Notes
modernc.org/sqlite(pure Go, no CGO) is used instead ofmattn/go-sqlite3, enabling cross-compilation withCGO_ENABLED=0and no system library dependency.- A
sync.Mutex(writeMu) on the component serialises allUnitOfWork.Docalls, preventingSQLITE_BUSYerrors that arise from SQLite's single-writer constraint without requiring callers to manage locking. - Foreign key enforcement is applied both via the
_fk=trueDSN pragma and an explicitPRAGMA foreign_keys = ONstatement inOnInit, ensuring enforcement is active regardless of driver-level pragma handling.