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
29class Transaction
final {
31 explicit Transaction(infra::ConnectionPtr&& connection,
32 engine::Deadline deadline);
34 Transaction(
const Transaction& other) =
delete;
35 Transaction(Transaction&& other)
noexcept;
44 template <
typename... Args>
45 StatementResultSet
Execute(
const Query& query,
const Args&... args)
const;
70 template <
typename Container>
72 const Container& params)
const;
89 template <
typename MapTo,
typename Container>
91 const Container& params)
const;
101 StatementResultSet DoExecute(
const Query& query,
102 impl::io::ParamsBinderBase& params)
const;
104 void AssertValid()
const;
106 utils::FastPimpl<infra::ConnectionPtr, 24, 8> connection_;
107 engine::Deadline deadline_;
111template <
typename... Args>
112StatementResultSet Transaction::
Execute(
const Query& query,
113 const Args&... args)
const {
114 auto params_binder = impl::BindHelper::BindParams(args...);
121 const T& row)
const {
122 auto params_binder = impl::BindHelper::BindRowAsParams(row);
124 return DoExecute(query, params_binder);
127template <
typename Container>
129 const Container& params)
const {
130 UINVARIANT(!params.empty(),
"Empty params in bulk execution");
132 auto params_binder = impl::BindHelper::BindContainerAsParams(params);
137template <
typename MapTo,
typename Container>
139 const Query& query,
const Container& params)
const {
140 UINVARIANT(!params.empty(),
"Empty params in bulk execution");
143 impl::BindHelper::BindContainerAsParamsMapped<MapTo>(params);