A current database connection for a body of code, opened only when something first uses it.
with-db-connection (and wrap-db-connection, for a Ring-style handler) makes a database available to its body without opening a connection. The connection is opened the first time current-db-connection is called (by a query, a transaction, or anything else that needs it), kept for the rest of the body, and closed (returned to its pool, for a pooled database) when the body ends. A body that never uses the database never opens a connection.
A current database connection for a body of code, opened only when something first uses it. with-db-connection (and wrap-db-connection, for a Ring-style handler) makes a database available to its body without opening a connection. The connection is opened the first time current-db-connection is called (by a query, a transaction, or anything else that needs it), kept for the rest of the body, and closed (returned to its pool, for a pooled database) when the body ends. A body that never uses the database never opens a connection.
(call-with-db-connection db-connection f)Call f with db-connection (a db-spec, such as a pool from sql-file.core/open-pool) available as the current database. A connection is opened only if f uses it, and is closed when f returns or throws. A db-spec that already has an open :connection is used as it is, and left open.
Call f with db-connection (a db-spec, such as a pool from sql-file.core/open-pool) available as the current database. A connection is opened only if f uses it, and is closed when f returns or throws. A db-spec that already has an open :connection is used as it is, and left open.
(current-db-connection)The current database, as a db-spec with an open :connection, connecting first if this is its first use. Fails if there is no current database.
The current database, as a db-spec with an open :connection, connecting first if this is its first use. Fails if there is no current database.
(wrap-db-connection app db-connection)Ring-style middleware: run each request with db-connection as the current database (see call-with-db-connection). Requests that don't use the database don't open a connection.
Ring-style middleware: run each request with db-connection as the current database (see call-with-db-connection). Requests that don't use the database don't open a connection.
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 |