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());
173 template <
typename... Args>
175 return Execute(OptionalCommandControl{}, query, args...);
186 template <
typename... Args>
188 const Query& query,
const Args&... args) {
189 detail::StaticQueryParameters<
sizeof...(args)> params;
190 params.Write(GetConnectionUserTypes(), args...);
191 return DoExecute(query, detail::QueryParameters{params}, statement_cmd_ctl);
202 return Execute(OptionalCommandControl{}, query, store);
217 template <
typename Container>
219 std::size_t chunk_rows = kDefaultRowsInChunk);
226 template <
typename Container>
227 void ExecuteBulk(OptionalCommandControl statement_cmd_ctl,
const Query& query,
228 const Container& args,
229 std::size_t chunk_rows = kDefaultRowsInChunk);
242 template <
typename Container>
244 std::size_t chunk_rows = kDefaultRowsInChunk);
257 template <
typename Container>
259 const Query& query,
const Container& args,
260 std::size_t chunk_rows = kDefaultRowsInChunk);
264 template <
typename... Args>
266 return MakePortal(OptionalCommandControl{}, query, args...);
271 template <
typename... Args>
273 const Query& query,
const Args&... args) {
274 detail::StaticQueryParameters<
sizeof...(args)> params;
275 params.Write(GetConnectionUserTypes(), args...);
276 return MakePortal(PortalName{}, query, detail::QueryParameters{params},
283 return MakePortal(OptionalCommandControl{}, query, store);
294 void SetParameter(
const std::string& param_name,
const std::string& value);
310 TimeoutDuration GetConnStatementTimeoutDebug()
const;
313 ResultSet DoExecute(
const Query& query,
const detail::QueryParameters& params,
314 OptionalCommandControl statement_cmd_ctl);
315 Portal MakePortal(
const PortalName&,
const Query& query,
316 const detail::QueryParameters& params,
317 OptionalCommandControl statement_cmd_ctl);
319 const UserTypes& GetConnectionUserTypes()
const;
321 detail::ConnectionPtr conn_;
324template <
typename Container>
326 std::size_t chunk_rows) {
327 auto split =
io::SplitContainer(args, chunk_rows);
328 for (
auto&& chunk : split) {
329 Execute(query, chunk);
333template <
typename Container>
335 const Query& query,
const Container& args,
336 std::size_t chunk_rows) {
337 auto split =
io::SplitContainer(args, chunk_rows);
338 for (
auto&& chunk : split) {
339 Execute(statement_cmd_ctl, query, chunk);
343template <
typename Container>
345 const Container& args,
346 std::size_t chunk_rows) {
347 io::SplitContainerByColumns(args, chunk_rows)
348 .Perform([&query,
this](
const auto&... args) {
349 this->Execute(query, args...);
353template <
typename Container>
356 const Container& args,
357 std::size_t chunk_rows) {
358 io::SplitContainerByColumns(args, chunk_rows)
359 .Perform([&query, &statement_cmd_ctl,
this](
const auto&... args) {
360 this->Execute(statement_cmd_ctl, query, args...);