Query execution with I/O, logging, and error handling.
This is part of the imperative shell - it performs database I/O, manages transactions, and handles side effects like logging.
Query execution with I/O, logging, and error handling. This is part of the imperative shell - it performs database I/O, manages transactions, and handles side effects like logging.
Bound transaction connection used by database execution helpers.
This ensures all nested database calls inside a transaction share the same JDBC connection instead of borrowing a new one from the pool.
Bound transaction connection used by database execution helpers. This ensures all nested database calls inside a transaction share the same JDBC connection instead of borrowing a new one from the pool.
(after-commit! f)Call f once the transaction with-transaction* holds open on this thread
commits, and never if it rolls back; with none open, now. For work another
system sees, such as a job on a queue outside the database.
Call `f` once the transaction `with-transaction*` holds open on this thread commits, and never if it rolls back; with none open, now. For work another system sees, such as a job on a queue outside the database.
(as-kebab-maps rs opts)next.jdbc builder-fn: unqualified maps keyed as snake-case->kebab-case-string
names a column, where the default splits digits off (e2e_id becomes
:e-2e-id). Opt in with :builder-fn on the db context.
next.jdbc builder-fn: unqualified maps keyed as `snake-case->kebab-case-string` names a column, where the default splits digits off (`e2e_id` becomes `:e-2e-id`). Opt in with `:builder-fn` on the db context.
(current-datasource ctx)Return the active JDBC executor for the current call.
Prefer a transaction-bound connection when present so transaction-scoped
settings like PostgreSQL search_path remain in effect for all downstream
queries.
Return the active JDBC executor for the current call. Prefer a transaction-bound connection when present so transaction-scoped settings like PostgreSQL `search_path` remain in effect for all downstream queries.
Check if value is a valid database context.
Delegates to pure core function.
Check if value is a valid database context. Delegates to pure core function.
(encode-params adapter [sql & params])[sql & params] with each param as the engine takes it (BOU-648). An
adapter without an encoder gets an Instant as its ISO string (BOU-655).
`[sql & params]` with each param as the engine takes it (BOU-648). An adapter without an encoder gets an Instant as its ISO string (BOU-655).
(execute-batch! ctx query-maps)Execute multiple queries in a single transaction.
Args: ctx: Database context query-maps: Vector of HoneySQL query maps
Returns: Vector of results (for SELECTs) or affected row counts (for updates)
Example: (execute-batch! ctx [{:insert-into :users :values [{:name "John"}]} {:insert-into :users :values [{:name "Jane"}]}])
Execute multiple queries in a single transaction.
Args:
ctx: Database context
query-maps: Vector of HoneySQL query maps
Returns:
Vector of results (for SELECTs) or affected row counts (for updates)
Example:
(execute-batch! ctx [{:insert-into :users :values [{:name "John"}]}
{:insert-into :users :values [{:name "Jane"}]}])(execute-one! ctx query-map)Execute query expecting single result.
Args: ctx: Database context query-map: HoneySQL query map
Returns: Single result map or nil
Example: (execute-one! ctx {:select [:*] :from [:users] :where [:= :id "123"]})
Execute query expecting single result.
Args:
ctx: Database context
query-map: HoneySQL query map
Returns:
Single result map or nil
Example:
(execute-one! ctx {:select [:*] :from [:users] :where [:= :id "123"]})(execute-query! ctx query-map)Execute SELECT query and return results.
SHELL FUNCTION: Performs database I/O and logging (side effects). Uses pure core functions for query formatting.
Args: ctx: Database context {:datasource ds :adapter adapter} query-map: HoneySQL query map
Returns: Vector of result maps
Example: (execute-query! ctx {:select [:*] :from [:users] :where [:= :active true]})
Execute SELECT query and return results.
SHELL FUNCTION: Performs database I/O and logging (side effects).
Uses pure core functions for query formatting.
Args:
ctx: Database context {:datasource ds :adapter adapter}
query-map: HoneySQL query map
Returns:
Vector of result maps
Example:
(execute-query! ctx {:select [:*] :from [:users] :where [:= :active true]})(execute-update! ctx query-map)Execute UPDATE/INSERT/DELETE query.
SHELL FUNCTION: Performs database I/O and logging (side effects).
Args: ctx: Database context query-map: HoneySQL query map
Returns: Number of affected rows
Example: (execute-update! ctx {:update :users :set {:active false} :where [:= :id "123"]})
Execute UPDATE/INSERT/DELETE query.
SHELL FUNCTION: Performs database I/O and logging (side effects).
Args:
ctx: Database context
query-map: HoneySQL query map
Returns:
Number of affected rows
Example:
(execute-update! ctx {:update :users :set {:active false} :where [:= :id "123"]})(forgetting-hooks-on-failure f)(f); when it throws, drop the after-commit hooks it added, as a savepoint
rollback drops its writes.
`(f)`; when it throws, drop the after-commit hooks it added, as a savepoint rollback drops its writes.
(redacted-cause e)(redacted-cause e {:keys [sql-state error-code] :as reported})e, or when the driver's message quotes the values sent, a SQLException in
its place saying what redaction/redacted-message says, with the same
state, code and stack. Whatever logs or reports the cause chain then reads
no values (BOU-628).
`e`, or when the driver's message quotes the values sent, a SQLException in its place saying what `redaction/redacted-message` says, with the same state, code and stack. Whatever logs or reports the cause chain then reads no values (BOU-628).
(remembered-in-transaction k f)(f), called until it answers truthy once per k for the transaction open
on this thread; with none open, each time. For a catalog answer such as a
table being there, which the transaction's locks keep true until it ends.
`(f)`, called until it answers truthy once per `k` for the transaction open on this thread; with none open, each time. For a catalog answer such as a table being there, which the transaction's locks keep true until it ends.
What the driver said. See redaction/reported.
What the driver said. See `redaction/reported`.
(transaction-on datasource)The connection of the transaction bound on this thread when it was opened
on datasource, else nil: a component holding another database's
datasource must not write into it.
The connection of the transaction bound on this thread when it was opened on `datasource`, else nil: a component holding another database's datasource must not write into it.
Validate that context has a valid adapter.
Delegates to pure core function.
Validate that context has a valid adapter. Delegates to pure core function.
Validate database context and throw if invalid.
Delegates to pure core function.
Validate database context and throw if invalid. Delegates to pure core function.
(with-transaction* ctx f)Execute function within database transaction context.
Args: ctx: Database context f: Function that takes transaction context and returns result
Returns: Result of function execution
Example: (with-transaction* ctx (fn [tx] (execute-update! tx query)))
Execute function within database transaction context. Args: ctx: Database context f: Function that takes transaction context and returns result Returns: Result of function execution Example: (with-transaction* ctx (fn [tx] (execute-update! tx query)))
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |