11#include <userver/clients/dns/resolver_fwd.hpp>
12#include <userver/components/component_fwd.hpp>
14#include <userver/storages/clickhouse/fwd.hpp>
15#include <userver/storages/clickhouse/impl/insertion_request.hpp>
16#include <userver/storages/clickhouse/impl/pool.hpp>
17#include <userver/storages/clickhouse/options.hpp>
18#include <userver/storages/clickhouse/query.hpp>
19#include <userver/utils/statistics/writer.hpp>
21USERVER_NAMESPACE_BEGIN
28struct ClickhouseSettings;
45 const impl::ClickhouseSettings& settings,
50 Cluster(
const Cluster&) =
delete;
54 template <
typename... Args>
55 ExecutionResult
Execute(
const Query& query,
const Args&... args)
const;
59 template <
typename... Args>
60 ExecutionResult
Execute(OptionalCommandControl,
const Query& query,
61 const Args&... args)
const;
70 void Insert(
const std::string& table_name,
71 const std::vector<std::string_view>& column_names,
82 void Insert(OptionalCommandControl,
const std::string& table_name,
83 const std::vector<std::string_view>& column_names,
97 template <
typename Container>
99 const std::vector<std::string_view>& column_names,
100 const Container& data)
const;
114 template <
typename Container>
115 void InsertRows(OptionalCommandControl,
const std::string& table_name,
116 const std::vector<std::string_view>& column_names,
117 const Container& data)
const;
121 USERVER_NAMESPACE::utils::statistics::Writer& writer)
const;
125 using std::runtime_error::runtime_error;
129 void DoInsert(OptionalCommandControl,
130 const impl::InsertionRequest& request)
const;
132 ExecutionResult DoExecute(OptionalCommandControl,
const Query& query)
const;
134 const impl::Pool& GetPool()
const;
136 std::vector<impl::Pool> pools_;
137 mutable std::atomic<std::size_t> current_pool_ind_{0};
141void Cluster::
Insert(
const std::string& table_name,
142 const std::vector<std::string_view>& column_names,
143 const T& data)
const {
144 Insert(OptionalCommandControl{}, table_name, column_names, data);
148void Cluster::
Insert(OptionalCommandControl optional_cc,
149 const std::string& table_name,
150 const std::vector<std::string_view>& column_names,
151 const T& data)
const {
153 impl::InsertionRequest::Create(table_name, column_names, data);
155 DoInsert(optional_cc, request);
158template <
typename Container>
160 const std::vector<std::string_view>& column_names,
161 const Container& data)
const {
162 InsertRows(OptionalCommandControl{}, table_name, column_names, data);
165template <
typename Container>
167 const std::string& table_name,
168 const std::vector<std::string_view>& column_names,
169 const Container& data)
const {
170 if (data.empty())
return;
173 impl::InsertionRequest::CreateFromRows(table_name, column_names, data);
175 DoInsert(optional_cc, request);
178template <
typename... Args>
179ExecutionResult Cluster::
Execute(
const Query& query,
180 const Args&... args)
const {
181 return Execute(OptionalCommandControl{}, query, args...);
184template <
typename... Args>
185ExecutionResult Cluster::
Execute(OptionalCommandControl optional_cc,
187 const Args&... args)
const {
188 const auto formatted_query = query.WithArgs(args...);
189 return DoExecute(optional_cc, formatted_query);