10#include <userver/clients/dns/resolver_fwd.hpp>
11#include <userver/components/component_fwd.hpp>
12#include <userver/engine/deadline.hpp>
13#include <userver/utils/statistics/writer.hpp>
15#include <userver/storages/mysql/cluster_host_type.hpp>
16#include <userver/storages/mysql/command_result_set.hpp>
17#include <userver/storages/mysql/cursor_result_set.hpp>
18#include <userver/storages/mysql/impl/bind_helper.hpp>
19#include <userver/storages/mysql/options.hpp>
20#include <userver/storages/mysql/query.hpp>
21#include <userver/storages/mysql/statement_result_set.hpp>
22#include <userver/storages/mysql/transaction.hpp>
24USERVER_NAMESPACE_BEGIN
32namespace infra::topology {
44 const settings::MysqlSettings& settings,
56 template <
typename... Args>
58 const Args&... args)
const;
72 template <
typename... Args>
73 StatementResultSet
Execute(OptionalCommandControl command_control,
75 const Args&... args)
const;
88 const Query& query,
const T& row)
const;
103 template <
typename T>
106 const Query& query,
const T& row)
const;
120 template <
typename Container>
122 const Container& params)
const;
140 template <
typename Container>
141 StatementResultSet
ExecuteBulk(OptionalCommandControl command_control,
143 const Container& params)
const;
160 template <
typename MapTo,
typename Container>
163 const Container& params)
const;
185 template <
typename MapTo,
typename Container>
189 const Container& params)
const;
203 Transaction
Begin(OptionalCommandControl command_control,
213 const Query& command)
const;
227 const Query& command)
const;
238 template <
typename T,
typename... Args>
240 std::size_t batch_size,
const Query& query,
241 const Args&... args)
const;
257 template <
typename T,
typename... Args>
258 CursorResultSet<T>
GetCursor(OptionalCommandControl command_control,
260 std::size_t batch_size,
const Query& query,
261 const Args&... args)
const;
267 static CommandControl GetDefaultCommandControl();
269 StatementResultSet DoExecute(OptionalCommandControl command_control,
271 impl::io::ParamsBinderBase& params,
272 std::optional<std::size_t> batch_size)
const;
274 std::unique_ptr<infra::topology::TopologyBase> topology_;
277template <
typename... Args>
280 const Args&... args)
const {
281 return Execute(std::nullopt, host_type, query, args...);
284template <
typename... Args>
285StatementResultSet Cluster::
Execute(OptionalCommandControl command_control,
288 const Args&... args)
const {
289 auto params_binder = impl::BindHelper::BindParams(args...);
291 return DoExecute(command_control, host_type, query.GetStatement(),
292 params_binder, std::nullopt);
298 const T& row)
const {
299 return ExecuteDecompose(std::nullopt, host_type, query, row);
305 const Query& query,
const T& row)
const {
306 auto params_binder = impl::BindHelper::BindRowAsParams(row);
308 return DoExecute(command_control, host_type, query, params_binder,
312template <
typename Container>
315 const Container& params)
const {
316 return ExecuteBulk(std::nullopt, host_type, query, params);
319template <
typename Container>
320StatementResultSet Cluster::
ExecuteBulk(OptionalCommandControl command_control,
323 const Container& params)
const {
324 UINVARIANT(!params.empty(),
"Empty params in bulk execution");
326 auto params_binder = impl::BindHelper::BindContainerAsParams(params);
328 return DoExecute(command_control, host_type, query.GetStatement(),
329 params_binder, std::nullopt);
332template <
typename MapTo,
typename Container>
335 const Container& params)
const {
336 return ExecuteBulkMapped<MapTo>(std::nullopt, host_type, query, params);
339template <
typename MapTo,
typename Container>
342 const Query& query,
const Container& params)
const {
343 UINVARIANT(!params.empty(),
"Empty params in bulk execution");
346 impl::BindHelper::BindContainerAsParamsMapped<MapTo>(params);
348 return DoExecute(command_control, host_type, query.GetStatement(),
349 params_binder, std::nullopt);
352template <
typename T,
typename... Args>
354 std::size_t batch_size,
356 const Args&... args)
const {
357 return GetCursor<T>(std::nullopt, host_type, batch_size, query, args...);
360template <
typename T,
typename... Args>
361CursorResultSet<T> Cluster::
GetCursor(OptionalCommandControl command_control,
363 std::size_t batch_size,
365 const Args&... args)
const {
366 auto params_binder = impl::BindHelper::BindParams(args...);
368 return CursorResultSet<T>{
369 DoExecute(command_control, host_type, query, params_binder, batch_size)};