Back

on-connection+options (clj)

(source)

macro

(on-connection+options [sym connectable] & body)
Given a connectable object, assumed to be wrapped with options, gets a connection, rewraps it with those options, and binds it to `sym`, then executes the `body` in that context. This allows you to write generic, **wrapped** connectable code without needing to know the exact type of an incoming datasource: ```clojure (on-connection+options [conn datasource] (execute! conn some-insert-sql) (execute! conn some-update-sql)) ``` If passed a `Connection` then that `Connection` is used as-is. If passed a `Connectable` that wraps a `Connection`, then that `Connectable` is used as-is. Otherwise, creates a new `Connection` object from the connectable, wraps that with options, executes the body, and automatically closes the new `Connection` for you. Note: the bound `sym` will be a **wrapped** connectable and not a plain Java object, so you cannot call JDBC methods directly on it like you can with `on-connection`.

Examples