vormia-go-driver-sqlite
Pure-Go SQLite driver for the Vormia Go framework. Thin wrapper around database/sql and modernc.org/sqlite that validates the shared Database contract with zero infrastructure — no Docker, no server, no C compiler.
Version: v1.1.0 — verified ready for vormia-go v1.2.x db.Wipe / seed.Run (catalog query, transactional DROP, :memory: pool pin). No API changes from v1.0.0.
Install
go get github.com/vormialabs/vormia-go-driver-sqlite@v1.1.0
Quick start
package main
import (
"context"
"fmt"
"log"
sqlite "github.com/vormialabs/vormia-go-driver-sqlite"
)
func main() {
db, err := sqlite.Open(sqlite.Config{
Path: ":memory:",
ForeignKeys: true,
})
if err != nil {
log.Fatal(err)
}
defer db.Close()
ctx := context.Background()
if _, err := db.ExecContext(ctx,
`CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT NOT NULL)`); err != nil {
log.Fatal(err)
}
if _, err := db.ExecContext(ctx,
`INSERT INTO users (name) VALUES (?)`, "Ada"); err != nil {
log.Fatal(err)
}
rows, err := db.QueryContext(ctx, `SELECT name FROM users WHERE name = ?`, "Ada")
if err != nil {
log.Fatal(err)
}
defer rows.Close()
for rows.Next() {
var name string
if err := rows.Scan(&name); err != nil {
log.Fatal(err)
}
fmt.Println(name)
}
}
Config
| Field |
Purpose |
Path |
File path, or :memory: for an in-memory database (default :memory:) |
ForeignKeys |
Enable FK enforcement (OFF by default in SQLite) |
BusyTimeoutMS |
Milliseconds to wait on a locked DB before erroring |
WAL |
Enable write-ahead logging for better file-DB concurrency |
For file databases with concurrent writes, set WAL: true and a BusyTimeoutMS (e.g. 5000).
Rebind
Apps write queries with ? placeholders. Call db.Rebind(q) before executing. SQLite's Rebind is the identity function; Postgres will convert ? → $1, $2, ….
q := db.Rebind(`SELECT * FROM users WHERE id = ?`)
rows, err := db.QueryContext(ctx, q, userID)
Wipe / seed readiness
vormia-go's db.Wipe and seed.Run call only the existing Database contract (QueryContext, ExecContext, BeginTx). This driver needs no wipe-specific helpers:
- Catalog enumeration uses a plain
SELECT against sqlite_master.
- SQLite supports transactional DDL, so wipe wraps drops in
BeginTx / Commit.
- Multi-step wipe/seed sequences on
:memory: share the single pinned connection (see gotcha 1).
Gotchas
:memory: + connection pool = data disappears. Each connection gets its own in-memory DB. Open pins :memory: to one connection via SetMaxOpenConns(1).
- Foreign keys are OFF by default. SQLite ignores
REFERENCES unless you set ForeignKeys: true.
- File DB concurrency. SQLite serializes writes. Use
WAL: true and BusyTimeoutMS for real workloads.
- Pragma DSN syntax is driver-specific. The
_pragma=... form is modernc.org/sqlite's. Switching to mattn/go-sqlite3 would require different DSN syntax.
Docs worth knowing
License
MIT