Back

on-connection (clj)

(source)

macro

(on-connection [sym connectable] & body)
Given a connectable object, gets a connection and binds it to `sym`, then executes the `body` in that context. This allows you to write generic, `Connection`-based code without needing to know the exact type of an incoming datasource: ```clojure (on-connection [conn datasource] (let [metadata (.getMetadata conn) catalog (.getCatalog conn)] ...)) ``` If passed a `Connection` or a `Connectable` that wraps a `Connection`, then that `Connection` is used as-is. Otherwise, creates a new `Connection` object from the connectable, executes the body, and automatically closes it for you.

Examples