Commits

Shantanu Kumar committed 58312ae

add `with-connection` macro (compatible with c.c.sql/with-connection)

  • Participants
  • Parent commits a24cb6a

Comments (0)

Files changed (1)

File src/main/clj/org/bituf/clj_dbspec.clj

         (apply (wrap-datasource-conn f) args)))))
 
 
+(defmacro with-connection
+  "Macro (like c.c.sql/with-connection) to execute body of code in the context
+  of a spec while ensuring that a connection exists."
+  [spec & body] {:pre [`(map? ~spec)]}
+  `(with-dbspec ~spec
+     (let [g# (wrap-connection (fn [] ~@body))]
+       (g#))))
+
+
 ;; ----- Factory functions for creating DB-Spec -----