5#include <userver/tracing/span.hpp>
6#include <userver/utils/fast_pimpl.hpp>
8#include <userver/storages/mysql/cluster_host_type.hpp>
9#include <userver/storages/mysql/command_result_set.hpp>
10#include <userver/storages/mysql/cursor_result_set.hpp>
11#include <userver/storages/mysql/impl/bind_helper.hpp>
12#include <userver/storages/mysql/options.hpp>
13#include <userver/storages/mysql/query.hpp>
14#include <userver/storages/mysql/statement_result_set.hpp>
16USERVER_NAMESPACE_BEGIN
18namespace storages::
mysql {
29class Transaction
final {
31 explicit Transaction(infra::ConnectionPtr&& connection, engine::Deadline deadline);
33 Transaction(
const Transaction& other) =
delete;
34 Transaction(Transaction&& other)
noexcept;
43 template <
typename... Args>
44 StatementResultSet
Execute(
const Query& query,
const Args&... args)
const;
69 template <
typename Container>
70 StatementResultSet
ExecuteBulk(
const Query& query,
const Container& params)
const;
87 template <
typename MapTo,
typename Container>
89 const Container& params)
const;
99 StatementResultSet DoExecute(
const Query& query, impl::io::ParamsBinderBase& params)
const;
101 void AssertValid()
const;
103 utils::FastPimpl<infra::ConnectionPtr, 24, 8> connection_;
104 engine::Deadline deadline_;
108template <
typename... Args>
109StatementResultSet Transaction::
Execute(
const Query& query,
const Args&... args)
const {
110 auto params_binder = impl::BindHelper::BindParams(args...);
117 auto params_binder = impl::BindHelper::BindRowAsParams(row);
119 return DoExecute(query, params_binder);
122template <
typename Container>
123StatementResultSet Transaction::
ExecuteBulk(
const Query& query,
const Container& params)
const {
124 UINVARIANT(!params.empty(),
"Empty params in bulk execution");
126 auto params_binder = impl::BindHelper::BindContainerAsParams(params);
131template <
typename MapTo,
typename Container>
132StatementResultSet Transaction::
ExecuteBulkMapped(
const Query& query,
const Container& params)
const {
133 UINVARIANT(!params.empty(),
"Empty params in bulk execution");
135 auto params_binder = impl::BindHelper::BindContainerAsParamsMapped<MapTo>(params);