-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.clj
31 lines (25 loc) · 893 Bytes
/
helpers.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
(ns utility-belt.sql.helpers
(:require
[next.jdbc]
[utility-belt.sql.model :as model]))
(defmacro with-transaction
"Wrapper around jdbc transaction macro. Cleans up imports so we always use ut.sql
Suports the same options, eg.
[tx conn]
and
[tx conn opts]
+ body."
[binding & body]
`(next.jdbc/with-transaction ~binding ~@body))
(defn execute
([connection statement]
(execute connection statement {:mode :kebab-maps}))
([connection statement {:keys [mode]}]
(next.jdbc/execute! connection statement
(get model/modes mode))))
(defn transaction?
"Detects if passed in data source is a transaction or not.
NOTE: this only works with HikariCP managed connections/transactions and the connection pool
defined in utility-belt.sql.component.connection-pool"
[tx-or-conn]
(-> tx-or-conn bean :transactionIsolation number?))