From a76189d9c8fb26d78da3412a3fe6dfc6edf39d0a Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Mon, 1 Apr 2019 23:43:10 -0700 Subject: [PATCH] Fix #4 by adding transact `with-transaction` now delegates to `transact` which in turn delegates to `p/-transact`. --- src/next/jdbc.clj | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/next/jdbc.clj b/src/next/jdbc.clj index 8825d13..b9ad926 100644 --- a/src/next/jdbc.clj +++ b/src/next/jdbc.clj @@ -156,6 +156,16 @@ ([connectable sql-params opts] (rs/execute-one! connectable sql-params opts))) +(defn transact + "Given a connectable object and a function (taking a Connection), + execute the function on a new connection in a transactional manner. + + An options map may be provided before the function." + ([connectable f] + (p/-transact connectable f {})) + ([connectable opts f] + (p/-transact connectable f opts))) + (defmacro with-transaction "Given a connectable object, gets a new connection and binds it to 'sym', then executes the 'body' in that context, committing any changes if the body @@ -167,7 +177,7 @@ * :read-only -- true / false, * :rollback-only -- true / false." [[sym connectable opts] & body] - `(p/-transact ~connectable (fn [~sym] ~@body) ~opts)) + `(transact ~connectable ~opts (fn [~sym] ~@body))) (defn insert! "Given a connectable object, a table name, and a data hash map, inserts the