PostgreSQL transaction. More...
#include <userver/storages/postgres/transaction.hpp>
Collaboration diagram for storages::postgres::Transaction:Shortcut transaction options constants | |
| static constexpr TransactionOptions | RW {} |
| Read-write read committed transaction. | |
| static constexpr TransactionOptions | RO {TransactionOptions::kReadOnly} |
| Read-only read committed transaction. | |
| static constexpr TransactionOptions | Deferrable |
| Read-only serializable deferrable transaction. | |
| static constexpr std::size_t | kDefaultRowsInChunk = 1024 |
| Transaction (Transaction &&) noexcept | |
| Transaction & | operator= (Transaction &&) noexcept |
| Transaction (const Transaction &)=delete | |
| Transaction & | operator= (const Transaction &)=delete |
Query execution | |
Execute statement with arbitrary parameters. Suspends coroutine for execution. std::size_t InsertInTransaction(storages::postgres::Transaction& transaction,
std::string_view key) {
auto res = transaction.Execute("INSERT INTO keys VALUES ($1)", key);
return res.RowsAffected();
}
| |
| template<typename... Args> | |
| ResultSet | Execute (const Query &query, const Args &... args) |
| template<typename... Args> | |
| ResultSet | Execute (OptionalCommandControl statement_cmd_ctl, const Query &query, const Args &... args) |
| ResultSet | Execute (const Query &query, const ParameterStore &store) |
| ResultSet | Execute (OptionalCommandControl statement_cmd_ctl, const Query &query, const ParameterStore &store) |
| template<typename Container > | |
| void | ExecuteBulk (const Query &query, const Container &args, std::size_t chunk_rows=kDefaultRowsInChunk) |
| template<typename Container > | |
| void | ExecuteBulk (OptionalCommandControl statement_cmd_ctl, const Query &query, const Container &args, std::size_t chunk_rows=kDefaultRowsInChunk) |
| template<typename Container > | |
| void | ExecuteDecomposeBulk (const Query &query, const Container &args, std::size_t chunk_rows=kDefaultRowsInChunk) |
| template<typename Container > | |
| void | ExecuteDecomposeBulk (OptionalCommandControl statement_cmd_ctl, const Query &query, const Container &args, std::size_t chunk_rows=kDefaultRowsInChunk) |
| template<typename... Args> | |
| Portal | MakePortal (const Query &query, const Args &... args) |
| template<typename... Args> | |
| Portal | MakePortal (OptionalCommandControl statement_cmd_ctl, const Query &query, const Args &... args) |
| Portal | MakePortal (const Query &query, const ParameterStore &store) |
| Portal | MakePortal (OptionalCommandControl statement_cmd_ctl, const Query &query, const ParameterStore &store) |
| void | SetParameter (const std::string ¶m_name, const std::string &value) |
| void | Commit () |
| void | Rollback () |
| OptionalCommandControl | GetConnTransactionCommandControlDebug () const |
| Used in tests. | |
| TimeoutDuration | GetConnStatementTimeoutDebug () const |
PostgreSQL transaction.
RAII wrapper for running transactions on PostgreSQL connections. Should be retrieved by calling storages::postgres::Cluster::Begin().
Non-copyable.
If the transaction is not explicitly finished (either committed or rolled back) it will roll itself back in the destructor.
Definition at line 136 of file transaction.hpp.
| void storages::postgres::Transaction::Commit | ( | ) |
Commit the transaction Suspends coroutine until command complete. After Commit or Rollback is called, the transaction is not usable any more.
|
inline |
Definition at line 174 of file transaction.hpp.
|
inline |
Execute statement with stored parameters.
Suspends coroutine for execution.
Definition at line 201 of file transaction.hpp.
|
inline |
Execute statement with arbitrary parameters and per-statement command control.
Suspends coroutine for execution.
Definition at line 187 of file transaction.hpp.
| ResultSet storages::postgres::Transaction::Execute | ( | OptionalCommandControl | statement_cmd_ctl, |
| const Query & | query, | ||
| const ParameterStore & | store | ||
| ) |
Execute statement with stored parameters and per-statement command control.
Suspends coroutine for execution.
| void storages::postgres::Transaction::ExecuteBulk | ( | const Query & | query, |
| const Container & | args, | ||
| std::size_t | chunk_rows = kDefaultRowsInChunk |
||
| ) |
Execute statement that uses an array of arguments splitting that array in chunks and executing the statement with a chunk of arguments.
Useful for statements that unnest their arguments to avoid the need to increase timeouts due to data amount growth.
Definition at line 325 of file transaction.hpp.
| void storages::postgres::Transaction::ExecuteBulk | ( | OptionalCommandControl | statement_cmd_ctl, |
| const Query & | query, | ||
| const Container & | args, | ||
| std::size_t | chunk_rows = kDefaultRowsInChunk |
||
| ) |
Execute statement that uses an array of arguments splitting that array in chunks and executing the statement with a chunk of arguments.
Useful for statements that unnest their arguments to avoid the need to increase timeouts due to data amount growth.
Definition at line 334 of file transaction.hpp.
| void storages::postgres::Transaction::ExecuteDecomposeBulk | ( | const Query & | query, |
| const Container & | args, | ||
| std::size_t | chunk_rows = kDefaultRowsInChunk |
||
| ) |
Execute statement that uses an array of arguments transforming that array into N arrays of corresponding fields and executing the statement with a chunk of each of these arrays values. Basically, a column-wise ExecuteBulk.
Useful for statements that unnest their arguments to avoid the need to increase timeouts due to data amount growth, but providing an explicit mapping from Container::value_type to PG type is infeasible for some reason (otherwise, use ExecuteBulk).
Definition at line 344 of file transaction.hpp.
| void storages::postgres::Transaction::ExecuteDecomposeBulk | ( | OptionalCommandControl | statement_cmd_ctl, |
| const Query & | query, | ||
| const Container & | args, | ||
| std::size_t | chunk_rows = kDefaultRowsInChunk |
||
| ) |
Execute statement that uses an array of arguments transforming that array into N arrays of corresponding fields and executing the statement with a chunk of each of these arrays values. Basically, a column-wise ExecuteBulk.
Useful for statements that unnest their arguments to avoid the need to increase timeouts due to data amount growth, but providing an explicit mapping from Container::value_type to PG type is infeasible for some reason (otherwise, use ExecuteBulk).
Definition at line 354 of file transaction.hpp.
|
inline |
Create a portal for fetching results of a statement with arbitrary parameters.
Definition at line 265 of file transaction.hpp.
|
inline |
Create a portal for fetching results of a statement with stored parameters.
Definition at line 282 of file transaction.hpp.
|
inline |
Create a portal for fetching results of a statement with arbitrary parameters and per-statement command control.
Definition at line 272 of file transaction.hpp.
| Portal storages::postgres::Transaction::MakePortal | ( | OptionalCommandControl | statement_cmd_ctl, |
| const Query & | query, | ||
| const ParameterStore & | store | ||
| ) |
Create a portal for fetching results of a statement with stored parameters and per-statement command control.
| void storages::postgres::Transaction::Rollback | ( | ) |
Rollback the transaction Suspends coroutine until command complete. After Commit or Rollback is called, the transaction is not usable any more.
| void storages::postgres::Transaction::SetParameter | ( | const std::string & | param_name, |
| const std::string & | value | ||
| ) |
Set a connection parameter https://www.postgresql.org/docs/current/sql-set.html The parameter is set for this transaction only
|
staticconstexpr |
Read-only serializable deferrable transaction.
Definition at line 145 of file transaction.hpp.
|
staticconstexpr |
Definition at line 149 of file transaction.hpp.
|
staticconstexpr |
Read-only read committed transaction.
Definition at line 143 of file transaction.hpp.
|
staticconstexpr |
Read-write read committed transaction.
Definition at line 141 of file transaction.hpp.