Improve with-atomic macro to accept cfg

This commit is contained in:
Andrey Antukh 2023-07-20 10:49:46 +02:00
parent d268ff2952
commit 27fb4c7ed9
3 changed files with 22 additions and 2 deletions

View file

@ -218,7 +218,13 @@
(defmacro with-atomic
[& args]
`(jdbc/with-transaction ~@args))
(if (symbol? (first args))
(let [cfgs (first args)
body (rest args)]
`(jdbc/with-transaction [conn# (::pool ~cfgs)]
(let [~cfgs (assoc ~cfgs ::conn conn#)]
~@body)))
`(jdbc/with-transaction ~@args)))
(defn open
[pool]