Correct documentation for transact and with-transaction
Previously both functions were documented as taking a `Connectable` object. This amends the documentation as well as the fn signature to take a `Transactable` object.
This commit is contained in:
parent
cbf10e581b
commit
df1c38c03f
3 changed files with 14 additions and 12 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
The `transact` function and `with-transaction` macro were briefly mentioned in the [Getting Started](/doc/getting-started.md) section but we'll go into more detail here.
|
||||
|
||||
Although `(transact connectable thunk)` is available, it is expected that you will mostly use `(with-transaction [tx connectable] body...)` when you want to execute multiple SQL operations in the context of a single transaction so that is what this section focuses on.
|
||||
Although `(transact transactable thunk)` is available, it is expected that you will mostly use `(with-transaction [tx transactable] body...)` when you want to execute multiple SQL operations in the context of a single transaction so that is what this section focuses on.
|
||||
|
||||
By default, all connections that `next.jdbc` creates are automatically committable, i.e., as each operation is performed, the effect is committed to the database directly before the next operation is performed. Any exceptions only cause the current operation to be aborted -- any prior operations have already been committed.
|
||||
|
||||
|
|
|
|||
|
|
@ -183,17 +183,17 @@
|
|||
(assoc opts :next.jdbc/sql-params sql-params))))
|
||||
|
||||
(defn transact
|
||||
"Given a connectable object and a function (taking a `Connection`),
|
||||
execute the function on a new connection in a transactional manner.
|
||||
"Given a transactable object and a function (taking a `Connection`),
|
||||
execute the function over the connection in a transactional manner.
|
||||
|
||||
See `with-transaction` for supported options."
|
||||
([connectable f]
|
||||
(p/-transact connectable f {}))
|
||||
([connectable f opts]
|
||||
(p/-transact connectable f opts)))
|
||||
([transactable f]
|
||||
(p/-transact transactable f {}))
|
||||
([transactable f opts]
|
||||
(p/-transact transactable f opts)))
|
||||
|
||||
(defmacro with-transaction
|
||||
"Given a connectable object, gets a new connection and binds it to `sym`,
|
||||
"Given a transactable object, gets a connection and binds it to `sym`,
|
||||
then executes the `body` in that context, committing any changes if the body
|
||||
completes successfully, otherwise rolling back any changes made.
|
||||
|
||||
|
|
@ -202,5 +202,5 @@
|
|||
`:repeatable-read`, `:serializable`,
|
||||
* `:read-only` -- `true` / `false`,
|
||||
* `:rollback-only` -- `true` / `false`."
|
||||
[[sym connectable opts] & body]
|
||||
`(transact ~connectable (^{:once true} fn* [~sym] ~@body) ~opts))
|
||||
[[sym transactable opts] & body]
|
||||
`(transact ~transactable (^{:once true} fn* [~sym] ~@body) ~opts))
|
||||
|
|
|
|||
|
|
@ -45,6 +45,8 @@
|
|||
(s/def ::key-map (s/map-of keyword? any?))
|
||||
(s/def ::opts-map (s/map-of keyword? any?))
|
||||
|
||||
(s/def ::transactable any?)
|
||||
|
||||
(s/def ::sql-params (s/and vector?
|
||||
(s/cat :sql string?
|
||||
:params (s/* any?))))
|
||||
|
|
@ -80,14 +82,14 @@
|
|||
:opts (s/? ::opts-map))))
|
||||
|
||||
(s/fdef jdbc/transact
|
||||
:args (s/cat :connectable ::connectable
|
||||
:args (s/cat :transactable ::transactable
|
||||
:f fn?
|
||||
:opts (s/? ::opts-map)))
|
||||
|
||||
(s/fdef jdbc/with-transaction
|
||||
:args (s/cat :binding (s/and vector?
|
||||
(s/cat :sym simple-symbol?
|
||||
:connectable ::connectable
|
||||
:transactable ::transactable
|
||||
:opts ::opts-map))
|
||||
:body (s/* any?)))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue