March Docs

Sqlite

lib/driver/sqlite.march SQLite backend driver for Depot.

Wraps libsqlite3 via March's C FFI. Resource destructors registered at first open() call handle sqlite3_close / sqlite3_finalize automatically via Perceus RC — no explicit cleanup needed in March code.

Public API: open_conn(path) : Result(Db.DbConn, String) Opens (or creates) a SQLite database and returns an abstract DbConn whose dispatch closures capture the sqlite3* resource. Only this module and code that calls open_conn need needs Ffi.

Internal helpers (not part of the public API): open / exec / query / replace_placeholders / replace_ilike

Functions

fnexecexec(db, sql, params)#

Execute a parameterized SQL statement against db.

sql must already use ? placeholders (not $N); call replace_placeholders first if the SQL came from the Depot query compiler.

Returns Ok({ columns, rows, tag }) matching the shape of Connection.exec_prepared so higher-level modules are backend-agnostic.

fnopen_connopen_conn(path)#

Open a SQLite database at path and return a Db.DbConn.

The returned DbConn wraps the sqlite3* resource in closures — callers only need needs Ffi when they import this module to call open_conn. Higher-level modules that receive a DbConn value do not need needs Ffi.

fnqueryquery(db, sql) do exec(db, sql, Nil) end#

Execute a simple (no-parameter) SQL statement against db.

fnreplace_ilikereplace_ilike(sql)#

Replace ILIKE with LIKE for SQLite compatibility.

SQLite does not support ILIKE. Its LIKE operator is case-insensitive for ASCII by default, which is equivalent for the typical use case.

fnreplace_placeholdersreplace_placeholders(sql)#

Replace Postgres-style $N parameter placeholders with SQLite ? placeholders.

The params list stays in order — SQLite ? is positional, just like Postgres $N.