userver: storages::postgres::QueryQueue Class Reference
Loading...
Searching...
No Matches
storages::postgres::QueryQueue Class Referencefinal

#include <userver/storages/postgres/query_queue.hpp>

Detailed Description

A container to enqueue queries in FIFO order and execute them all within a single network round-trip.

Acquired from storages::postgres::Cluster, one is expected to Push some queries into the queue and then Collect them into vector of results.

From a client point of view Collect is transactional: either all the queries succeed or Collect rethrows the first error encountered. However, this is NOT the case for the server: server treats all the provided queries independently and is likely to execute subsequent queries even after prior failures.

Warning
If an explicit transaction ("BEGIN") or a modifying query is added into the queue the behavior is unspecified. Don't do that.
Note
Queries may or may not be sent to the server prior to Collect call.
Requires both pipelining and prepared statements to be enabled in the driver, UINVARIANTS (that is, throws in release builds and aborts in debug ones) that on construction.

Definition at line 41 of file query_queue.hpp.

Public Member Functions

 QueryQueue (CommandControl default_cc, detail::ConnectionPtr &&conn)
 
 QueryQueue (QueryQueue &&) noexcept
 
QueryQueueoperator= (QueryQueue &&) noexcept
 
 QueryQueue (const QueryQueue &)=delete
 
QueryQueueoperator= (const QueryQueue &)=delete
 
void Reserve (std::size_t size)
 Reserve internal storage to hold this amount of queries.
 
template<typename... Args>
void Push (CommandControl cc, const Query &query, const Args &... args)
 
template<typename... Args>
void Push (const Query &query, const Args &... args)
 Add a query into the queue with default command-control.
 
std::vector< ResultSetCollect (TimeoutDuration timeout)
 
std::vector< ResultSetCollect ()
 

Member Function Documentation

◆ Collect() [1/2]

std::vector< ResultSet > storages::postgres::QueryQueue::Collect ( )

Collect results of all the queued queries, with default timeout. Either returns a vector of N ResultSets, where N is the number of queries enqueued, or rethrow the first error encountered, be that a query execution error or a timeout.

◆ Collect() [2/2]

std::vector< ResultSet > storages::postgres::QueryQueue::Collect ( TimeoutDuration timeout)

Collect results of all the queued queries, with specified timeout. Either returns a vector of N ResultSets, where N is the number of queries enqueued, or rethrow the first error encountered, be that a query execution error or a timeout.

◆ Push() [1/2]

template<typename... Args>
void storages::postgres::QueryQueue::Push ( CommandControl cc,
const Query & query,
const Args &... args )

Add a query into the queue with specified command-control. CommandControl is used as following: 'execute' is used as a timeout for preparing the statement (if needed), 'statement' is used as a statement timeout for later execution.

Definition at line 102 of file query_queue.hpp.

◆ Push() [2/2]

template<typename... Args>
void storages::postgres::QueryQueue::Push ( const Query & query,
const Args &... args )

Add a query into the queue with default command-control.

Definition at line 111 of file query_queue.hpp.


The documentation for this class was generated from the following file: