Skip to main content

Module connection

Module connection 

Source
Expand description

Connection lifecycle for mempill-sqlite.

Every connection — whether backed by a file or opened in-memory — MUST have the mandatory PRAGMAs applied before migrations run or any write is served.

§PRAGMA contract

PRAGMA journal_mode = WAL;      -- WAL for concurrent reads during writes
PRAGMA synchronous  = FULL;     -- full-durability write path (WAL+NORMAL can lose writes on power loss)
PRAGMA foreign_keys = ON;       -- enforce FK constraints from v1_initial.sql

§In-memory WAL caveat

SQLite silently downgrades journal_mode to memory for :memory: connections because WAL requires a real file (it writes a -wal and -shm sidecar). This is expected and documented behaviour. The durability guarantees (synchronous=FULL and foreign_keys=ON) are still applied and tested for in-memory connections. WAL mode is tested separately against a temporary file-backed database.

Functions§

open
Open a file-backed SQLite connection at path, apply mandatory PRAGMAs, then run any pending migrations.
open_in_memory
Open an in-memory SQLite connection, apply mandatory PRAGMAs (except WAL — see module-level caveat), then run migrations.