451a089d5859a227a06e4f57fd26302769d9e1ba
sqlite
Pure-Go SQLite client (modernc.org/sqlite, no CGO) with launcher lifecycle and health check integration.
Install
go get code.nochebuena.dev/go/sqlite
Usage
db := sqlite.New(logger, cfg)
lc.Append(db)
r.Get("/health", health.NewHandler(logger, db))
Testing with :memory:
db := sqlite.New(logger, sqlite.Config{Path: ":memory:"})
db.OnInit()
Unit of Work
uow := sqlite.NewUnitOfWork(logger, db)
err := uow.Do(ctx, func(ctx context.Context) error {
exec := db.GetExecutor(ctx) // returns the active Tx
_, err := exec.ExecContext(ctx, "INSERT INTO orders ...")
return err
})
The UnitOfWork serialises writes via an internal mutex to prevent SQLITE_BUSY errors.
Configuration
| Env var | Default | Description |
|---|---|---|
SQLITE_PATH |
required | File path or :memory: |
SQLITE_MAX_OPEN_CONNS |
1 |
Max open connections |
SQLITE_MAX_IDLE_CONNS |
1 |
Max idle connections |
SQLITE_PRAGMAS |
?_journal=WAL&_timeout=5000&_fk=true |
DSN pragmas |
Foreign key enforcement (PRAGMA foreign_keys = ON) is always enabled in OnInit.
Releases
2
Release v1.0.0
Latest
Languages
Go
100%