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
149 static constexpr std::size_t kDefaultRowsInChunk = 1024;
152 explicit Transaction(detail::ConnectionPtr&& conn,
154 OptionalCommandControl trx_cmd_ctl = {},
155 detail::SteadyClock::time_point trx_start_time =
156 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>
190 const Query& query,
const Args&... args) {
191 detail::StaticQueryParameters<
sizeof...(args)> params;
192 params.Write(GetConnectionUserTypes(), args...);
193 return DoExecute(query, detail::QueryParameters{params}, statement_cmd_ctl);
204 return Execute(OptionalCommandControl{}, query, store);
219 template <
typename Container>
220 void ExecuteBulk(
const Query& query,
const Container& args,
221 std::size_t chunk_rows = kDefaultRowsInChunk);
228 template <
typename Container>
229 void ExecuteBulk(OptionalCommandControl statement_cmd_ctl,
const Query& query,
230 const Container& args,
231 std::size_t chunk_rows = kDefaultRowsInChunk);
244 template <
typename Container>
246 std::size_t chunk_rows = kDefaultRowsInChunk);
259 template <
typename Container>
261 const Query& query,
const Container& args,
262 std::size_t chunk_rows = kDefaultRowsInChunk);
266 template <
typename... Args>
268 return MakePortal(OptionalCommandControl{}, query, args...);
273 template <
typename... Args>
275 const Query& query,
const Args&... args) {
276 detail::StaticQueryParameters<
sizeof...(args)> params;
277 params.Write(GetConnectionUserTypes(), args...);
278 return MakePortal(PortalName{}, query, detail::QueryParameters{params},
285 return MakePortal(OptionalCommandControl{}, query, store);
296 void SetParameter(
const std::string& param_name,
const std::string& value);
312 TimeoutDuration GetConnStatementTimeoutDebug()
const;
315 ResultSet DoExecute(
const Query& query,
const detail::QueryParameters& params,
316 OptionalCommandControl statement_cmd_ctl);
317 Portal MakePortal(
const PortalName&,
const Query& query,
318 const detail::QueryParameters& params,
319 OptionalCommandControl statement_cmd_ctl);
321 const UserTypes& GetConnectionUserTypes()
const;
324 detail::ConnectionPtr conn_;
327template <
typename Container>
329 std::size_t chunk_rows) {
330 auto split =
io::SplitContainer(args, chunk_rows);
331 for (
auto&& chunk : split) {
332 Execute(query, chunk);
336template <
typename Container>
338 const Query& query,
const Container& args,
339 std::size_t chunk_rows) {
340 auto split =
io::SplitContainer(args, chunk_rows);
341 for (
auto&& chunk : split) {
342 Execute(statement_cmd_ctl, query, chunk);
346template <
typename Container>
348 const Container& args,
349 std::size_t chunk_rows) {
350 io::SplitContainerByColumns(args, chunk_rows)
351 .Perform([&query,
this](
const auto&... args) {
352 this->Execute(query, args...);
356template <
typename Container>
359 const Container& args,
360 std::size_t chunk_rows) {
361 io::SplitContainerByColumns(args, chunk_rows)
362 .Perform([&query, &statement_cmd_ctl,
this](
const auto&... args) {
363 this->Execute(statement_cmd_ctl, query, args...);