Transactions support for clojure.jdbc
WARNING: This namespace is deprecated and will be removed in clojure.jdbc 0.6.0.
Transactions support for clojure.jdbc WARNING: This namespace is deprecated and will be removed in clojure.jdbc 0.6.0.
Default transaction strategy implementation.
Default transaction strategy implementation.
(call-in-transaction
  conn
  func
  &
  [{:keys [savepoints strategy] :or {savepoints true} :as opts}])Wrap function in one transaction.
This function accepts as a parameter a transaction strategy. If no one
is specified, DefaultTransactionStrategy is used.
With DefaultTransactionStrategy, if current connection is already in
transaction, it uses truly nested transactions for properly handle it.
The availability of this feature depends on database support for it.
Example:
(with-connection dbspec conn (call-in-transaction conn (fn [conn] (execute! conn 'DROP TABLE foo;'))))
For more idiomatic code, you should use with-transaction macro.
Depending on transaction strategy you are using, this function can accept additional parameters. The default transaction strategy exposes two additional parameters:
:isolation-level - set isolation level for this transaction:read-only - set current transaction to read onlyWrap function in one transaction. This function accepts as a parameter a transaction strategy. If no one is specified, `DefaultTransactionStrategy` is used. With `DefaultTransactionStrategy`, if current connection is already in transaction, it uses truly nested transactions for properly handle it. The availability of this feature depends on database support for it. Example: (with-connection dbspec conn (call-in-transaction conn (fn [conn] (execute! conn 'DROP TABLE foo;')))) For more idiomatic code, you should use `with-transaction` macro. Depending on transaction strategy you are using, this function can accept additional parameters. The default transaction strategy exposes two additional parameters: - `:isolation-level` - set isolation level for this transaction - `:read-only` - set current transaction to read only
(is-rollback-set? conn)Check if a current connection in one transaction is marked for rollback.
This should be used in one transaction, in other case this function always return false.
Check if a current connection in one transaction is marked for rollback. This should be used in one transaction, in other case this function always return false.
(set-rollback! conn)Mark a current connection for rollback.
It ensures that on the end of the current transaction instead of commit changes, rollback them.
This function should be used inside of a transaction block, otherwise this function does nothing.
Example:
(with-transaction conn (make-some-queries-without-changes conn) (set-rollback! conn))
Mark a current connection for rollback. It ensures that on the end of the current transaction instead of commit changes, rollback them. This function should be used inside of a transaction block, otherwise this function does nothing. Example: (with-transaction conn (make-some-queries-without-changes conn) (set-rollback! conn))
(unset-rollback! conn)Revert flag setted by set-rollback! function.
This function should be used inside of a transaction
block, otherwise this function does nothing.
Revert flag setted by `set-rollback!` function. This function should be used inside of a transaction block, otherwise this function does nothing.
(with-transaction conn & body)Creates a context that evaluates in transaction (or nested transaction). This is a more idiomatic way to execute some database operations in atomic way.
Example:
(with-transaction conn (execute! conn 'DROP TABLE foo;') (execute! conn 'DROP TABLE bar;'))
Also, you can pass additional options to transaction:
(with-transaction conn {:read-only true} (execute! conn 'DROP TABLE foo;') (execute! conn 'DROP TABLE bar;'))
Creates a context that evaluates in transaction (or nested transaction).
This is a more idiomatic way to execute some database operations in
atomic way.
Example:
(with-transaction conn
  (execute! conn 'DROP TABLE foo;')
  (execute! conn 'DROP TABLE bar;'))
Also, you can pass additional options to transaction:
(with-transaction conn {:read-only true}
  (execute! conn 'DROP TABLE foo;')
  (execute! conn 'DROP TABLE bar;'))
(with-transaction-strategy conn strategy & body)Set some transaction strategy connection in the current context scope. This method not uses thread-local dynamic variables and connection preserves a transaction strategy throught threads.
Set some transaction strategy connection in the current context scope. This method not uses thread-local dynamic variables and connection preserves a transaction strategy throught threads.
(wrap-transaction-strategy conn strategy)Simple helper function that associate a strategy to a connection and return a new connection object with wrapped stragy.
Example:
(let [conn (wrap-transaction-strategy simplecon (MyStrategy.))] (use-your-new-conn conn))
Simple helper function that associate a strategy to a connection and return a new connection object with wrapped stragy. Example: (let [conn (wrap-transaction-strategy simplecon (MyStrategy.))] (use-your-new-conn conn))
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs | 
| ← | Move to previous article | 
| → | Move to next article | 
| Ctrl+/ | Jump to the search field |