9#include <userver/storages/postgres/detail/connection_ptr.hpp>
10#include <userver/storages/postgres/detail/query_parameters.hpp>
11#include <userver/storages/postgres/detail/time_types.hpp>
12#include <userver/storages/postgres/options.hpp>
13#include <userver/storages/postgres/parameter_store.hpp>
14#include <userver/storages/postgres/portal.hpp>
15#include <userver/storages/postgres/postgres_fwd.hpp>
16#include <userver/storages/postgres/query.hpp>
17#include <userver/storages/postgres/result_set.hpp>
19USERVER_NAMESPACE_BEGIN
148 static constexpr std::size_t kDefaultRowsInChunk = 1024;
151 explicit Transaction(
152 detail::ConnectionPtr&& conn,
154 OptionalCommandControl trx_cmd_ctl = {},
155 detail::SteadyClock::time_point trx_start_time = detail::SteadyClock::now()
158 void SetName(std::string name);
175 template <
typename... Args>
176 ResultSet Execute(
const Query& query,
const Args&... args) {
177 return Execute(OptionalCommandControl{}, query, args...);
188 template <
typename... Args>
189 ResultSet Execute(OptionalCommandControl statement_cmd_ctl,
const Query& query,
const Args&... args) {
190 detail::StaticQueryParameters<
sizeof...(args)> params;
191 params.Write(GetConnectionUserTypes(), args...);
192 return DoExecute(query, detail::QueryParameters{params}, statement_cmd_ctl);
203 return Execute(OptionalCommandControl{}, query, store);
221 template <
typename Container>
222 void ExecuteBulk(
const Query& query,
const Container& args, std::size_t chunk_rows = kDefaultRowsInChunk);
229 template <
typename Container>
231 OptionalCommandControl statement_cmd_ctl,
233 const Container& args,
234 std::size_t chunk_rows = kDefaultRowsInChunk
248 template <
typename Container>
249 void ExecuteDecomposeBulk(
const Query& query,
const Container& args, std::size_t chunk_rows = kDefaultRowsInChunk);
262 template <
typename Container>
264 OptionalCommandControl statement_cmd_ctl,
266 const Container& args,
267 std::size_t chunk_rows = kDefaultRowsInChunk
272 template <
typename... Args>
274 return MakePortal(OptionalCommandControl{}, query, args...);
279 template <
typename... Args>
280 Portal MakePortal(OptionalCommandControl statement_cmd_ctl,
const Query& query,
const Args&... args) {
281 detail::StaticQueryParameters<
sizeof...(args)> params;
282 params.Write(GetConnectionUserTypes(), args...);
283 return MakePortal(PortalName{}, query, detail::QueryParameters{params}, statement_cmd_ctl);
289 return MakePortal(OptionalCommandControl{}, query, store);
299 void SetParameter(
const std::string& param_name,
const std::string& value);
315 TimeoutDuration GetConnStatementTimeoutDebug()
const;
319 DoExecute(
const Query& query,
const detail::QueryParameters& params, OptionalCommandControl statement_cmd_ctl);
323 const detail::QueryParameters& params,
324 OptionalCommandControl statement_cmd_ctl
327 const UserTypes& GetConnectionUserTypes()
const;
330 detail::ConnectionPtr conn_;
333template <
typename Container>
335 auto split = io::SplitContainer(args, chunk_rows);
336 for (
auto&& chunk : split) {
337 Execute(query, chunk);
341template <
typename Container>
343 OptionalCommandControl statement_cmd_ctl,
345 const Container& args,
346 std::size_t chunk_rows
348 auto split = io::SplitContainer(args, chunk_rows);
349 for (
auto&& chunk : split) {
350 Execute(statement_cmd_ctl, query, chunk);
354template <
typename Container>
356 io::SplitContainerByColumns(args, chunk_rows).Perform([&query,
this](
const auto&... args) {
357 this->Execute(query, args...);
361template <
typename Container>
363 OptionalCommandControl statement_cmd_ctl,
365 const Container& args,
366 std::size_t chunk_rows
368 io::SplitContainerByColumns(args, chunk_rows).Perform([&query, &statement_cmd_ctl,
this](
const auto&... args) {
369 this->Execute(statement_cmd_ctl, query, args...);