module Clear::SQL::Transaction
Direct including types
Defined in:
clear/sql/transaction.crInstance Method Summary
-
#after_commit(connection : String = "default", &block : DB::Connection -> Nil)
Register a callback function which will be fired once when SQL
COMMIT
operation is called -
#in_transaction?(connection : String = "default")
Check whether the current pair of fiber/connection is in transaction block or not.
-
#rollback(to = nil)
Rollback a transaction or return to the previous savepoint in case of a with_savepoint block.
-
#rollback_transaction
Rollback the transaction.
-
#transaction(connection : String = "default", level : Level = Level::Serializable, &)
Enter new transaction block for the current connection/fiber pair.
-
#with_savepoint(sp_name : Symbolic? = nil, connection_name : String = "default", &)
Create a transaction, but this one is stackable using savepoints.
Instance Method Detail
Register a callback function which will be fired once when SQL COMMIT
operation is called
This can be used for example to send email, or perform others tasks when you want to be sure the data is secured in the database.
transaction do
@user = User.find(1)
@user.subscribe!
Clear::SQL.after_commit { Email.deliver(ConfirmationMail.new(@user)) }
end
In case the transaction fail and eventually rollback, the code won't be called.
Check whether the current pair of fiber/connection is in transaction block or not.
Rollback a transaction or return to the previous savepoint in case of a
with_savepoint block.
The params to
offer
Rollback the transaction. In case the call is made inside a savepoint block rollback everything.
Enter new transaction block for the current connection/fiber pair.
Example:
Clear::SQL.transaction do
# do something
Clear::SQL.transaction do # Technically, this block do nothing, since we already are in transaction
rollback # < Rollback the up-most `transaction` block.
end
end
see #with_savepoint to use a stackable version using savepoints.
Create a transaction, but this one is stackable using savepoints.
Example:
Clear::SQL.with_savepoint do
# do something
Clear::SQL.with_savepoint do
rollback # < Rollback only the last `with_savepoint` block
end
end