mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
minimal docs for transactions
This commit is contained in:
parent
ed3ed71501
commit
d7ccecae9b
3 changed files with 25 additions and 0 deletions
|
@ -1,7 +1,16 @@
|
||||||
module DB
|
module DB
|
||||||
module BeginTransaction
|
module BeginTransaction
|
||||||
|
# Creates a transaction from the current context.
|
||||||
|
# If is expected that either `Transaction#commit` or `Transaction#rollback`
|
||||||
|
# are called explictly to release the context.
|
||||||
abstract def begin_transaction : Transaction
|
abstract def begin_transaction : Transaction
|
||||||
|
|
||||||
|
# yields a transaction from the current context.
|
||||||
|
# Query the database through `Transaction#connection` object.
|
||||||
|
# If an exception is thrown within the block a rollback is performed.
|
||||||
|
# The exception thrown is blubbled unless it is a `DB::Rollback`.
|
||||||
|
# From the yielded object `Transaction#commit` or `Transaction#rollback`
|
||||||
|
# can be called explicitly.
|
||||||
def transaction
|
def transaction
|
||||||
tx = begin_transaction
|
tx = begin_transaction
|
||||||
begin
|
begin
|
||||||
|
|
|
@ -105,6 +105,8 @@ module DB
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# yields a `Transaction` from a connection of the pool
|
||||||
|
# Refer to `BeginTransaction#transaction` for documentation.
|
||||||
def transaction
|
def transaction
|
||||||
using_connection do |cnn|
|
using_connection do |cnn|
|
||||||
cnn.transaction do |tx|
|
cnn.transaction do |tx|
|
||||||
|
|
|
@ -1,14 +1,28 @@
|
||||||
module DB
|
module DB
|
||||||
|
# Transactions should be started from `DB#transaction`, `Connection#transaction`
|
||||||
|
# or `Connection#begin_transaction`.
|
||||||
|
#
|
||||||
|
# Use `Transaction#connection` to submit statements to the database.
|
||||||
|
#
|
||||||
|
# Use `Transaction#commit` or `Transaction#rollback` to close the ongoing transaction
|
||||||
|
# explicitly. Or refer to `BeginTransaction#transaction` for documentation on how to
|
||||||
|
# use `#transaction(&block)` methods in `DB` and `Connection`.
|
||||||
|
#
|
||||||
|
# Nested transactions are supported by using sql `SAVEPOINT`. To start a nested
|
||||||
|
# transaction use `Transaction#transaction` or `Transaction#begin_transaction`.
|
||||||
|
#
|
||||||
abstract class Transaction
|
abstract class Transaction
|
||||||
include Disposable
|
include Disposable
|
||||||
include BeginTransaction
|
include BeginTransaction
|
||||||
|
|
||||||
abstract def connection : Connection
|
abstract def connection : Connection
|
||||||
|
|
||||||
|
# commits the current transaction
|
||||||
def commit
|
def commit
|
||||||
close!
|
close!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# rollbacks the current transaction
|
||||||
def rollback
|
def rollback
|
||||||
close!
|
close!
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue