services/storage/db

Database connection helpers. Thin wrappers around sqlight. Path resolution (e.g. ~ expansion) is handled by config.gleam before the path reaches this module.

Values

pub fn checkpoint_wal(
  conn: sqlight.Connection,
) -> Result(Nil, String)

Execute PRAGMA wal_checkpoint(TRUNCATE).

pub fn close(conn: sqlight.Connection) -> Result(Nil, String)

Close a database connection.

pub fn open(path: String) -> Result(sqlight.Connection, String)

Open a SQLite database at the given path.

pub fn pragma_integrity_check(
  conn: sqlight.Connection,
) -> Result(String, String)

Run PRAGMA integrity_check and return the result string.

pub fn service(path: String) -> service.Service

Service shape — supervised: True. The supervisor (Wave 4) wraps this in an actor for OTP lifecycle management. Here, start validates the DB path and health checks integrity.

pub fn transaction(
  conn: sqlight.Connection,
  f: fn(sqlight.Connection) -> Result(a, String),
) -> Result(a, String)

Execute a function within a SQLite transaction. BEGIN TRANSACTION → fn(conn) → COMMIT (on Ok) or ROLLBACK (on Error).

pub fn write_with_retry(
  conn: sqlight.Connection,
  sql: String,
  with params: List(sqlight.Value),
) -> Result(Nil, String)

Execute a write SQL statement with retry on SQLITE_BUSY.

Search Document