Module /postgres/client #
Pooled PostgreSQL client supporting primary/replica cluster routing, strong vs eventual consistency queries (query, query-strong, query-one, query-one-strong), batch execution, and ACID transactions.
(use /postgres/client)
begin #
(begin pool) -> Transaction
Begins a new ACID database transaction on the connection pool or primary writer.
command #
(command pool sql params?) -> Int
Executes a DDL or DML statement on the primary writer and returns the affected row count.
connect #
(connect config) -> Pool
Establishes a connection or connection pool using a URI string or configuration Map.
exec #
(exec pool sql params?) -> Int
Executes a SQL statement (INSERT, UPDATE, DELETE) on the primary writer and returns the number of affected rows.
exec-batch #
(exec-batch pool sql) -> None
Executes a multi-statement SQL script (such as schema migrations) in a single batch.
get-reader #
(get-reader ...)
Exported function in /postgres/client.
get-writer #
(get-writer ...)
Exported function in /postgres/client.
is-cluster? #
(is-cluster? ...)
Exported function in /postgres/client.
pool-stats #
(pool-stats ...)
Exported function in /postgres/client.
pool-status #
(pool-status ...)
Exported function in /postgres/client.
query #
(query pool sql params?) -> (Array Map)
Executes a SELECT query (routed to read replicas when configured) and returns an Array of row Maps.
query-exists-strong? #
(query-exists-strong? ...)
Exported function in /postgres/client.
query-exists? #
(query-exists? ...)
Exported function in /postgres/client.
query-maps #
(query-maps ...)
Exported function in /postgres/client.
query-maps-strong #
(query-maps-strong ...)
Exported function in /postgres/client.
query-one #
(query-one pool sql params?) -> (Or Map None)
Executes a query and returns the first matching row Map, or () if no rows match.
query-one-strong #
(query-one-strong pool sql params?) -> (Or Map None)
Executes a single-row query strictly on the primary writer connection (INSERT/UPDATE ... RETURNING or post-mutation reads).
query-one-tuple #
(query-one-tuple ...)
Exported function in /postgres/client.
query-scalar #
(query-scalar ...)
Exported function in /postgres/client.
query-scalar-strong #
(query-scalar-strong ...)
Exported function in /postgres/client.
query-strong #
(query-strong pool sql params?) -> (Array Map)
Executes a query strictly on the primary writer connection to guarantee read-after-write consistency (required for INSERT/UPDATE ... RETURNING).
query-tuples #
(query-tuples ...)
Exported function in /postgres/client.
query-tuples-one #
(query-tuples-one ...)
Exported function in /postgres/client.
query-tuples-one-strong #
(query-tuples-one-strong ...)
Exported function in /postgres/client.
query-tuples-strong #
(query-tuples-strong ...)
Exported function in /postgres/client.
Module /sqlite/client #
Embedded SQLite connection pool supporting parameterized SQL queries, row maps, and transactions.
(use /sqlite/client)
begin #
(sqlite/begin conn (Func [tx] ...)) -> Any
Executes closure inside a database transaction, committing on success or rolling back on Error.
changes #
(changes ...)
Exported function in /sqlite/client.
command #
(command pool sql params?) -> Int
Executes a DDL or DML statement on the primary writer and returns the affected row count.
connect #
(sqlite/connect path) -> Connection
Opens or creates an SQLite database connection.
(let db (sqlite/connect "app.db"))
exec #
(sqlite/exec conn sql ...params) -> Int
Executes INSERT/UPDATE/DELETE statement, returning number of affected rows.
(sqlite/exec db "UPDATE users SET status = ? WHERE id = ?" "active" 10)
exec-batch #
(exec-batch pool sql) -> None
Executes a multi-statement SQL script (such as schema migrations) in a single batch.
get-reader #
(get-reader ...)
Exported function in /sqlite/client.
get-writer #
(get-writer ...)
Exported function in /sqlite/client.
is-cluster? #
(is-cluster? ...)
Exported function in /sqlite/client.
pool-stats #
(pool-stats ...)
Exported function in /sqlite/client.
pool-status #
(pool-status ...)
Exported function in /sqlite/client.
query #
(sqlite/query conn sql ...params) -> Array
Executes SQL query and returns rows as an Array of Maps.
(let rows (sqlite/query db "SELECT id, name FROM users WHERE active = ?" 1))
query-exists-strong? #
(query-exists-strong? ...)
Exported function in /sqlite/client.
query-exists? #
(sqlite/query-exists? conn sql ...params) -> Bool
Executes SQL query and returns true if at least one row matches (or if a single boolean column is true), or false if empty.
(ok-or (await (sqlite/query-exists? db "SELECT 1 FROM users WHERE id = ?" id)) false)
query-maps #
(query-maps ...)
Exported function in /sqlite/client.
query-maps-strong #
(query-maps-strong ...)
Exported function in /sqlite/client.
query-one #
(sqlite/query-one conn sql ...params) -> (Or Map)
Executes SQL query and returns first matching row Map, or () if empty.
query-one-strong #
(query-one-strong pool sql params?) -> (Or Map None)
Executes a single-row query strictly on the primary writer connection (INSERT/UPDATE ... RETURNING or post-mutation reads).
query-one-tuple #
(query-one-tuple ...)
Exported function in /sqlite/client.
query-scalar #
(sqlite/query-scalar conn sql ...params) -> (Or Any)
Executes SQL query and returns column 0 of the first matching row directly as a scalar, or () if empty.
(ok-or (await (sqlite/query-scalar db "SELECT COUNT(*) FROM users")) 0)
query-scalar-strong #
(query-scalar-strong ...)
Exported function in /sqlite/client.
query-strong #
(query-strong pool sql params?) -> (Array Map)
Executes a query strictly on the primary writer connection to guarantee read-after-write consistency (required for INSERT/UPDATE ... RETURNING).
query-tuples #
(query-tuples ...)
Exported function in /sqlite/client.
query-tuples-one #
(query-tuples-one ...)
Exported function in /sqlite/client.
query-tuples-one-strong #
(query-tuples-one-strong ...)
Exported function in /sqlite/client.
query-tuples-strong #
(query-tuples-strong ...)
Exported function in /sqlite/client.