Skip to content

Instantly share code, notes, and snippets.

@bizenn
Created December 22, 2011 07:34
Show Gist options
  • Save bizenn/1509383 to your computer and use it in GitHub Desktop.
Save bizenn/1509383 to your computer and use it in GitHub Desktop.
with-connections -- Handling database multi-connection explicitly
(require '[clojure.java.jdbc :as sql])
(defmacro with-connections
""
[bindings & body]
(cond (empty? bindings) `(do ~@body)
(symbol? (bindings 0)) `(sql/with-connection ~(bindings 1)
(let [~(bindings 0) (sql/connection)]
(with-connections ~(subvec bindings 2) ~@body)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment