userver: storages::mysql::Transaction Class Reference
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
storages::mysql::Transaction Class Referencefinal

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

#include </data/code/service_template/third_party/userver/mysql/include/userver/storages/mysql/transaction.hpp>

Public Member Functions

 Transaction (infra::ConnectionPtr &&connection, engine::Deadline deadline)
 
 Transaction (const Transaction &other)=delete
 
 Transaction (Transaction &&other) noexcept
 
template<typename... Args>
StatementResultSet Execute (const Query &query, const Args &... args) const
 Executes a statement with default deadline. Fills placeholders of the statement with args..., Args are expected to be of supported types. See userver_mysql_types for better understanding of Args requirements.
 
template<typename T >
StatementResultSet ExecuteDecompose (const Query &query, const T &row) const
 Executes a statement with default deadline.
 
template<typename Container >
StatementResultSet ExecuteBulk (const Query &query, const Container &params) const
 Executes a statement with default deadline. Fills placeholders of the statements with Container::value_type in a bulk-manner. Container is expected to be a std::Container, Container::value_type is expected to be an aggregate of supported types. See userver_mysql_types for better understanding of Container::value_type requirements.
 
template<typename MapTo , typename Container >
StatementResultSet ExecuteBulkMapped (const Query &query, const Container &params) const
 Executes a statement with default deadline, on the flight remapping from Container::value_type to MapTo. Container is expected to be a std::Container of whatever type pleases you, MapTo is expected to be an aggregate of supported types. See userver_mysql_types for better understanding of MapTo requirements. You are expected to provide a converter function MapTo Convert(const Container::value_type&, storages::mysql::convert::To<MapTo>) in namespace of MapTo or storages::mysql::convert.
 
void Commit ()
 Commit the transaction.
 
void Rollback ()
 Rollback the transaction.
 

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::mysql::Cluster

Definition at line 29 of file transaction.hpp.

Member Function Documentation

◆ Execute()

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

Executes a statement with default deadline. Fills placeholders of the statement with args..., Args are expected to be of supported types. See userver_mysql_types for better understanding of Args requirements.

UINVARIANTs on params count mismatch doesn't validate types.

Definition at line 112 of file transaction.hpp.

◆ ExecuteBulk()

template<typename Container >
StatementResultSet storages::mysql::Transaction::ExecuteBulk ( const Query query,
const Container &  params 
) const

Executes a statement with default deadline. Fills placeholders of the statements with Container::value_type in a bulk-manner. Container is expected to be a std::Container, Container::value_type is expected to be an aggregate of supported types. See userver_mysql_types for better understanding of Container::value_type requirements.

Note
Requires MariaDB 10.2.6+ as a server

UINVARIANTs on params count mismatch, doesn't validate types. UINVARIANTs on empty params container.

Definition at line 128 of file transaction.hpp.

◆ ExecuteBulkMapped()

template<typename MapTo , typename Container >
StatementResultSet storages::mysql::Transaction::ExecuteBulkMapped ( const Query query,
const Container &  params 
) const

Executes a statement with default deadline, on the flight remapping from Container::value_type to MapTo. Container is expected to be a std::Container of whatever type pleases you, MapTo is expected to be an aggregate of supported types. See userver_mysql_types for better understanding of MapTo requirements. You are expected to provide a converter function MapTo Convert(const Container::value_type&, storages::mysql::convert::To<MapTo>) in namespace of MapTo or storages::mysql::convert.

Note
Requires MariaDB 10.2.6+ as a server

UINVARIANTs on params count mismatch, doesn't validate types. UINVARIANTs on empty params container.

Definition at line 138 of file transaction.hpp.

◆ ExecuteDecompose()

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

Executes a statement with default deadline.

Basically an alias for Execute(host_type, query, AsArgs<T>(row)), where AsArgs is an imaginary function which passes fields of T as variadic params. Handy for one-liner inserts. See userver_mysql_types for better understanding of T requirements.

UINVARIANTs on params count mismatch, doesn't validate types.

Definition at line 120 of file transaction.hpp.


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