userver: storages::sqlite::Transaction Class Reference
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
storages::sqlite::Transaction Class Referencefinal

#include <userver/storages/sqlite/transaction.hpp>

Detailed Description

RAII transaction wrapper, auto-ROLLBACKs on destruction if no prior Commit/Rollback call was made.

This type can't be constructed in user code and is always retrieved from storages::sqlite::Client

Definition at line 24 of file transaction.hpp.

Public Member Functions

 Transaction (std::shared_ptr< infra::ConnectionPtr > connection, const settings::TransactionOptions &options)
 
 Transaction (const Transaction &other)=delete
 
 Transaction (Transaction &&other) noexcept
 
Transactionoperator= (Transaction &&) noexcept
 
template<typename... Args>
ResultSet Execute (const Query &query, const Args &... args) const
 Executes a statement.
 
template<typename T>
ResultSet ExecuteDecompose (const Query &query, const T &row) const
 Executes a statement, decomposing the row.
 
template<typename Container>
void ExecuteMany (const Query &query, const Container &params) const
 Executes a statement multiple times.
 
template<typename T, typename... Args>
CursorResultSet< T > GetCursor (std::size_t batch_size, const Query &query, const Args &... args) const
 Executes a statement and returns a cursor for iterating over results.
 
Savepoint Save (std::string name) const
 Creates a savepoint with specified name.
 
void Commit ()
 Commit the transaction.
 
void Rollback ()
 Rollback the transaction.
 

Member Function Documentation

◆ Execute()

template<typename... Args>
ResultSet storages::sqlite::Transaction::Execute ( const Query & query,
const Args &... args ) const

Executes a statement.

Fills placeholders of the statement with args..., Args are expected to be of supported types. See SQLite supported types for better understanding of Args requirements.

Template Parameters
ArgsTypes of parameters to bind
Parameters
querySQL query to execute
argsParameters to bind to the query
Returns
ResultSet containing the results of the query

Definition at line 111 of file transaction.hpp.

◆ ExecuteDecompose()

template<typename T>
ResultSet storages::sqlite::Transaction::ExecuteDecompose ( const Query & query,
const T & row ) const

Executes a statement, decomposing the row.

Decomposes the fields of the row and binds them as parameters to the query. See SQLite supported types for better understanding of T requirements.

Template Parameters
TType of the row to decompose
Parameters
querySQL query to execute
rowRow object to decompose and bind
Returns
ResultSet containing the results of the query

Definition at line 124 of file transaction.hpp.

◆ ExecuteMany()

template<typename Container>
void storages::sqlite::Transaction::ExecuteMany ( const Query & query,
const Container & params ) const

Executes a statement multiple times.

Iterates over the container and executes the query for each element. Container is expected to be a std::Container, Container::value_type is expected to be an aggregate of supported types. See MySQL supported types for better understanding of Container::value_type requirements.

Template Parameters
ContainerType of the container holding rows
Parameters
querySQL query to execute
paramsContainer of rows to bind and execute

Definition at line 137 of file transaction.hpp.

◆ GetCursor()

template<typename T, typename... Args>
CursorResultSet< T > storages::sqlite::Transaction::GetCursor ( std::size_t batch_size,
const Query & query,
const Args &... args ) const

Executes a statement and returns a cursor for iterating over results.

Fills placeholders of the statement with args..., Args are expected to be of supported types. See SQLite supported types for better understanding of Args requirements.

Template Parameters
TType of the result rows
ArgsTypes of parameters to bind
Parameters
batch_sizeNumber of rows to fetch per batch
querySQL query to execute
argsParameters to bind to the query
Returns
CursorResultSet for iterating over the results

Definition at line 152 of file transaction.hpp.

◆ Save()

Savepoint storages::sqlite::Transaction::Save ( std::string name) const

Creates a savepoint with specified name.

Parameters
nameName of the savepoint
Returns
Savepoint object representing the created savepoint

The documentation for this class was generated from the following file: