|
relx 0.1.0
A Modern C++23 Type-Safe SQL Query Builder
|
RAII wrapper for database transactions. More...
#include <relx/connection/transaction_guard.hpp>
Public Member Functions | |
| TransactionGuard (Connection &connection, IsolationLevel isolation_level=IsolationLevel::ReadCommitted) | |
| Constructor that begins a transaction. | |
| ~TransactionGuard () noexcept | |
| Destructor that rolls back the transaction if it wasn't committed or rolled back. | |
| TransactionGuard (const TransactionGuard &)=delete | |
| TransactionGuard & | operator= (const TransactionGuard &)=delete |
| TransactionGuard (TransactionGuard &&other) noexcept | |
| TransactionGuard & | operator= (TransactionGuard &&other) noexcept |
| void | commit () |
| Commit the transaction. | |
| void | rollback () |
| Roll back the transaction. | |
| bool | is_committed () const noexcept |
| Check if the transaction has been committed. | |
| bool | is_rolled_back () const noexcept |
| Check if the transaction has been rolled back. | |
Static Public Member Functions | |
| template<typename Func > | |
| static void | with_transaction (Connection &connection, Func &&func, IsolationLevel isolation_level=IsolationLevel::ReadCommitted) |
| Execute a query within the transaction and commit on success. | |
RAII wrapper for database transactions.
Automatically begins a transaction on construction and either commits or rolls back on destruction, depending on whether commit() was called or an error occurred.
Definition at line 31 of file transaction_guard.hpp.
|
inlineexplicit |
Constructor that begins a transaction.
| connection | The database connection to use |
| isolation_level | The isolation level for the transaction |
| TransactionException | if the transaction cannot be started |
Definition at line 37 of file transaction_guard.hpp.
|
inlinenoexcept |
Destructor that rolls back the transaction if it wasn't committed or rolled back.
Definition at line 47 of file transaction_guard.hpp.
|
delete |
|
inlinenoexcept |
Definition at line 62 of file transaction_guard.hpp.
|
inline |
Commit the transaction.
| TransactionException | if the commit fails |
Definition at line 92 of file transaction_guard.hpp.
|
inlinenoexcept |
Check if the transaction has been committed.
Definition at line 122 of file transaction_guard.hpp.
|
inlinenoexcept |
Check if the transaction has been rolled back.
Definition at line 126 of file transaction_guard.hpp.
|
delete |
|
inlinenoexcept |
Definition at line 69 of file transaction_guard.hpp.
|
inline |
Roll back the transaction.
| TransactionException | if the rollback fails |
Definition at line 107 of file transaction_guard.hpp.
|
inlinestatic |
Execute a query within the transaction and commit on success.
| Func | A callable that executes database operations |
| func | The function to execute within the transaction |
| Any | exception thrown by func, or TransactionException for transaction errors |
Definition at line 133 of file transaction_guard.hpp.