Transactions
Transactions
The Transactions module manages transaction contexts stored in a session. It provides cursor-stability transactions, ACID snapshot/OCC transactions, commit, rollback, and implicit autocommit wrapping.
These functions are runtime primitives used by the SQL frontend. Applications normally use BEGIN, COMMIT, and ROLLBACK; see Transactions and Isolation for visibility, conflict, and durability semantics.
tx_begin
Begins a new cursor-stability transaction. Takes the session function as argument. Stores the transaction context in the session.
Allowed number of parameters: 1–1
Parameters
- session (
func): the session function to store tx state in- Parameters
- key (
string) (optional) - value (
any) (optional)
- key (
- Returns
- value (
any)
- value (
- Parameters
Returns
- value (
bool)
tx_begin_acid
Begins a new ACID transaction with snapshot isolation and OCC commit. Takes the session function as argument.
Allowed number of parameters: 1–1
Parameters
- session (
func): the session function to store tx state in- Parameters
- key (
string) (optional) - value (
any) (optional)
- key (
- Returns
- value (
any)
- value (
- Parameters
Returns
- value (
bool)
tx_commit
Commits the current transaction.
Allowed number of parameters: 1–1
Parameters
- session (
func): the session function that holds tx state- Parameters
- key (
string) (optional) - value (
any) (optional)
- key (
- Returns
- value (
any)
- value (
- Parameters
Returns
- value (
bool)
tx_rollback
Rolls back the current transaction.
Allowed number of parameters: 1–1
Parameters
- session (
func): the session function that holds tx state- Parameters
- key (
string) (optional) - value (
any) (optional)
- key (
- Returns
- value (
any)
- value (
- Parameters
Returns
- value (
bool)
with_autocommit
Executes fn inside an implicit TxCursorStability transaction if no explicit transaction is active in session. Commits on success, rolls back on error, and re-raises any panic so the caller's error handler still fires. If an explicit transaction is active (session["transaction"] != nil), fn is executed without any wrapping.
Allowed number of parameters: 2–2
Parameters
- session (
func): the session function holding tx state- Parameters
- key (
string) (optional) - value (
any) (optional)
- key (
- Returns
- value (
any)
- value (
- Parameters
- fn (
func): zero-argument function to execute- Returns
- value (
any)
- value (
- Returns
Returns
- value (
any)