/sqlite/client
Synchronous embedded SQLite connection pool with parameterized queries, row maps, and closure transactions (begin).
Functions & symbols#
begin#
Runs `callback` inside an ACID database transaction (or nested SAVEPOINT if already in a transaction), automatically committing on success or rolling back on error. Executes synchronously on the embedded runtime and returns the value directly (do not use `await`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
conn | Pool | Transaction | required | Connection pool, writer, or parent Transaction (creates savepoint) |
callback | Func | required | Transaction body `(Func tx ...)` — commits on normal return, rolls back on error or thrown panic |
Any(db/begin conn (Func tx
(db/exec tx #sql "UPDATE accounts SET balance = balance - 10 WHERE id = ?" [1])
))changes#
Returns the number of rows modified by the most recent SQLite statement on the connection.
| Parameter | Type | Optional | Description |
|---|---|---|---|
conn | Pool | Transaction | required | SQLite pool or active Transaction |
Any(let affected (sqlite/changes db))command#
Executes a SQL command/DDL statement on the primary writer and returns the affected row count. Executes synchronously on the embedded runtime and returns the value directly (do not use `await`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
conn | Pool | Transaction | required | Database connection pool, cluster, or active Transaction |
sql | String | required | Parameterized `#sql` query using ? placeholders |
params | Array | optional | Optional positional bind arguments |
Any(db/command conn "CREATE TABLE IF NOT EXISTS items (id INTEGER PRIMARY KEY, name TEXT)")connect#
Opens a SQL connection pool (or primary/reader cluster when `:reader-uri` / `:reader` is provided). Executes synchronously on the embedded runtime and returns the value directly (do not use `await`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
config | String | Map | required | Connection URI string or config Map {:uri ... :reader-uri ... :max-connections ...} |
Any(let db (sqlite/connect "./data.sqlite"))exec#
Executes a DML statement (`INSERT`, `UPDATE`, `DELETE`) on the primary writer and returns affected rows. Executes synchronously on the embedded runtime and returns the value directly (do not use `await`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
conn | Pool | Transaction | required | Database connection pool, cluster, or active Transaction |
sql | String | required | Parameterized `#sql` query using ? placeholders |
params | Array | optional | Optional positional bind arguments |
Any(db/exec conn #sql "DELETE FROM sessions WHERE id = ?" [sid])exec-batch#
Executes a batch of raw semicolon-separated SQL statements on the primary writer (useful for migrations). Executes synchronously on the embedded runtime and returns the value directly (do not use `await`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
conn | Pool | Transaction | required | Connection pool or writer |
sql | String | required | Multi-statement SQL script (e.g. schema migration) |
Any(db/exec-batch conn migration-sql)get-reader#
Returns the read-replica pool handle (or writer pool in single-node setups).
| Parameter | Type | Optional | Description |
|---|---|---|---|
pool | Pool | required | Database cluster or pool |
Any(let reader (db/get-reader pool))get-writer#
Returns the underlying primary writer pool handle.
| Parameter | Type | Optional | Description |
|---|---|---|---|
pool | Pool | required | Database cluster or pool |
Any(let writer (db/get-writer pool))is-cluster?#
Returns `true` if `pool` was configured with separate writer and read-replica pools.
| Parameter | Type | Optional | Description |
|---|---|---|---|
pool | Pool | required | Database connection pool |
Any(db/is-cluster? pool)pool-stats#
Alias for `pool-status`: returns live connection pool utilization metrics.
| Parameter | Type | Optional | Description |
|---|---|---|---|
pool | Pool | required | Database connection pool |
Any(db/pool-stats pool)pool-status#
Returns connection pool health metrics (active connections, idle count, capacity).
| Parameter | Type | Optional | Description |
|---|---|---|---|
pool | Pool | required | Database connection pool |
Any(db/pool-status pool)query#
Executes a `SELECT` query (routed to read replicas when configured, so reads are eventually consistent) and returns an Array of row Maps. Executes synchronously on the embedded runtime and returns the value directly (do not use `await`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
conn | Pool | Transaction | required | Database connection pool, cluster, or active Transaction |
sql | String | required | Parameterized `#sql` query using ? placeholders |
params | Array | optional | Optional positional bind arguments |
Any(db/query conn #sql "SELECT id, name FROM users WHERE active = ?" [true])query-exists-strong?#
Primary-writer variant of `query-exists?` guaranteeing strong consistency. Executes synchronously on the embedded runtime and returns the value directly (do not use `await`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
conn | Pool | Transaction | required | Database connection pool, cluster, or active Transaction |
sql | String | required | Parameterized `#sql` query using ? placeholders |
params | Array | optional | Optional positional bind arguments |
Any(db/query-exists-strong? conn #sql "SELECT 1 FROM users WHERE id = ?" [id])query-exists?#
Returns `true` if the SQL query matches at least one row. Executes synchronously on the embedded runtime and returns the value directly (do not use `await`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
conn | Pool | Transaction | required | Database connection pool, cluster, or active Transaction |
sql | String | required | Parameterized `#sql` query using ? placeholders |
params | Array | optional | Optional positional bind arguments |
Any(db/query-exists? conn #sql "SELECT 1 FROM users WHERE email = ?" [email])query-maps#
Executes a `SELECT` query and returns each row as a Map. Executes synchronously on the embedded runtime and returns the value directly (do not use `await`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
conn | Pool | Transaction | required | Database connection pool, cluster, or active Transaction |
sql | String | required | Parameterized `#sql` query using ? placeholders |
params | Array | optional | Optional positional bind arguments |
Any(db/query-maps conn #sql "SELECT * FROM items WHERE org_id = ?" [org-id])query-maps-strong#
Primary-writer variant of `query-maps` guaranteeing linearizable read-after-write visibility. Executes synchronously on the embedded runtime and returns the value directly (do not use `await`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
conn | Pool | Transaction | required | Database connection pool, cluster, or active Transaction |
sql | String | required | Parameterized `#sql` query using ? placeholders |
params | Array | optional | Optional positional bind arguments |
Any(db/query-maps-strong conn #sql "UPDATE items SET done = true WHERE id = ? RETURNING *" [id])query-one#
Executes a query and returns the first row as a `Map`, or `()` (`None`) if zero rows matched. Executes synchronously on the embedded runtime and returns the value directly (do not use `await`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
conn | Pool | Transaction | required | Database connection pool, cluster, or active Transaction |
sql | String | required | Parameterized `#sql` query using ? placeholders |
params | Array | optional | Optional positional bind arguments |
Any(db/query-one conn #sql "SELECT * FROM users WHERE id = ?" [id])query-one-strong#
Executes a single-row query on the primary writer (`INSERT/UPDATE ... RETURNING` or immediate post-write lookup), returning a `Map` or `()`. Executes synchronously on the embedded runtime and returns the value directly (do not use `await`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
conn | Pool | Transaction | required | Database connection pool, cluster, or active Transaction |
sql | String | required | Parameterized `#sql` query using ? placeholders |
params | Array | optional | Optional positional bind arguments |
Any(db/query-one-strong conn #sql "INSERT INTO users (name) VALUES (?) RETURNING id, name" ["Ada"])query-one-tuple#
Alias for `query-tuples-one`: returns the first row as an Array or `()`. Executes synchronously on the embedded runtime and returns the value directly (do not use `await`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
conn | Pool | Transaction | required | Database connection pool, cluster, or active Transaction |
sql | String | required | Parameterized `#sql` query using ? placeholders |
params | Array | optional | Optional positional bind arguments |
Any(db/query-one-tuple conn #sql "SELECT id, email FROM users WHERE id = ?" [id])query-scalar#
Executes a query expecting one column from the first row and returns that scalar value (or `()` if empty). Executes synchronously on the embedded runtime and returns the value directly (do not use `await`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
conn | Pool | Transaction | required | Database connection pool, cluster, or active Transaction |
sql | String | required | Parameterized `#sql` query using ? placeholders |
params | Array | optional | Optional positional bind arguments |
Any(db/query-scalar conn #sql "SELECT count(*) FROM users")query-scalar-strong#
Primary-writer variant of `query-scalar` for strong read-after-write scalar queries. Executes synchronously on the embedded runtime and returns the value directly (do not use `await`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
conn | Pool | Transaction | required | Database connection pool, cluster, or active Transaction |
sql | String | required | Parameterized `#sql` query using ? placeholders |
params | Array | optional | Optional positional bind arguments |
Any(db/query-scalar-strong conn #sql "INSERT INTO jobs (name) VALUES (?) RETURNING id" [name])query-strong#
Executes a query strictly on the primary writer for strong read-after-write consistency (required for `INSERT/UPDATE/DELETE ... RETURNING`). Executes synchronously on the embedded runtime and returns the value directly (do not use `await`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
conn | Pool | Transaction | required | Database connection pool, cluster, or active Transaction |
sql | String | required | Parameterized `#sql` query using ? placeholders |
params | Array | optional | Optional positional bind arguments |
Any(db/query-strong conn #sql "INSERT INTO users (email) VALUES (?) RETURNING *" [email])query-tuples#
Executes a query and returns rows as positional Arrays of column values. Executes synchronously on the embedded runtime and returns the value directly (do not use `await`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
conn | Pool | Transaction | required | Database connection pool, cluster, or active Transaction |
sql | String | required | Parameterized `#sql` query using ? placeholders |
params | Array | optional | Optional positional bind arguments |
Any(db/query-tuples conn #sql "SELECT id, title FROM posts")query-tuples-one#
Executes a query and returns the first row as an Array of positional columns, or `()`. Executes synchronously on the embedded runtime and returns the value directly (do not use `await`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
conn | Pool | Transaction | required | Database connection pool, cluster, or active Transaction |
sql | String | required | Parameterized `#sql` query using ? placeholders |
params | Array | optional | Optional positional bind arguments |
Any(db/query-tuples-one conn #sql "SELECT id, email FROM users WHERE id = ?" [id])query-tuples-one-strong#
Primary-writer variant of `query-tuples-one` guaranteeing strong consistency. Executes synchronously on the embedded runtime and returns the value directly (do not use `await`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
conn | Pool | Transaction | required | Database connection pool, cluster, or active Transaction |
sql | String | required | Parameterized `#sql` query using ? placeholders |
params | Array | optional | Optional positional bind arguments |
Any(db/query-tuples-one-strong conn #sql "INSERT INTO tags (slug) VALUES (?) RETURNING id, slug" [slug])query-tuples-strong#
Primary-writer variant of `query-tuples` for read-after-write consistency. Executes synchronously on the embedded runtime and returns the value directly (do not use `await`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
conn | Pool | Transaction | required | Database connection pool, cluster, or active Transaction |
sql | String | required | Parameterized `#sql` query using ? placeholders |
params | Array | optional | Optional positional bind arguments |
Any(db/query-tuples-strong conn #sql "SELECT id, title FROM posts")