userver: storages::postgres::ResultSet Class Reference
Loading...
Searching...
No Matches
storages::postgres::ResultSet Class Reference

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

Detailed Description

PostgreSQL result set.

Provides random access to rows via indexing operations and bidirectional iteration via iterators.

Usage synopsis

auto trx = ...;
auto res = trx.Execute("select a, b from table");
for (auto row : res) {
// Process row data
}
Examples
samples/digest_auth_service/auth_digest.cpp, and samples/postgres_service/postgres_service.cpp.

Definition at line 586 of file result_set.hpp.

Public Types

using size_type = std::size_t
 
using difference_type = std::ptrdiff_t
 

Public Member Functions

Forward iteration
const_iterator cbegin () const &
 
const_iterator begin () const &
 
const_iterator cend () const &
 
const_iterator end () const &
 
const_iterator cbegin () const &&=delete
 
const_iterator begin () const &&=delete
 
const_iterator cend () const &&=delete
 
const_iterator end () const &&=delete
 
Reverse iteration
const_reverse_iterator crbegin () const &
 
const_reverse_iterator rbegin () const &
 
const_reverse_iterator crend () const &
 
const_reverse_iterator rend () const &
 
const_reverse_iterator crbegin () const &&=delete
 
const_reverse_iterator rbegin () const &&=delete
 
const_reverse_iterator crend () const &&=delete
 
const_reverse_iterator rend () const &&=delete
 
reference Front () const &
 
reference Back () const &
 
reference Front () const &&=delete
 
reference Back () const &&=delete
 
reference operator[] (size_type index) const &
 Access a row by index.
 
reference operator[] (size_type index) const &&=delete
 
ResultSet metadata access
size_type FieldCount () const
 
RowDescription GetRowDescription () const &
 
RowDescription GetRowDescription () const &&=delete
 

Static Public Attributes

static constexpr size_type npos = std::numeric_limits<size_type>::max()
 

Row container concept

using const_iterator = ConstRowIterator
 
using const_reverse_iterator = ReverseConstRowIterator
 
using value_type = Row
 
using reference = value_type
 
using pointer = const_iterator
 
 ResultSet (std::shared_ptr< detail::ResultWrapper > pimpl)
 
size_type Size () const
 Number of rows in the result set.
 
bool IsEmpty () const
 
size_type RowsAffected () const
 
std::string CommandStatus () const
 

Typed results

template<typename T , typename Tag >
class TypedResultSet
 
class ConnectionImpl
 
template<typename T >
auto AsSetOf () const
 Get a wrapper for iterating over a set of typed results. For more information see psql_typed_results.
 
template<typename T >
auto AsSetOf (RowTag) const
 
template<typename T >
auto AsSetOf (FieldTag) const
 
template<typename Container >
Container AsContainer () const
 Extract data into a container. For more information see psql_typed_results.
 
template<typename Container >
Container AsContainer (RowTag) const
 
template<typename T >
auto AsSingleRow () const
 Extract first row into user type. A single row result set is expected, will throw an exception when result set size != 1.
 
template<typename T >
auto AsSingleRow (RowTag) const
 
template<typename T >
auto AsSingleRow (FieldTag) const
 
template<typename T >
std::optional< T > AsOptionalSingleRow () const
 Extract first row into user type.
 
template<typename T >
std::optional< T > AsOptionalSingleRow (RowTag) const
 
template<typename T >
std::optional< T > AsOptionalSingleRow (FieldTag) const
 

Member Typedef Documentation

◆ const_iterator

◆ const_reverse_iterator

◆ difference_type

using storages::postgres::ResultSet::difference_type = std::ptrdiff_t

Definition at line 589 of file result_set.hpp.

◆ pointer

◆ reference

◆ size_type

using storages::postgres::ResultSet::size_type = std::size_t

Definition at line 588 of file result_set.hpp.

◆ value_type

Definition at line 597 of file result_set.hpp.

Constructor & Destructor Documentation

◆ ResultSet()

storages::postgres::ResultSet::ResultSet ( std::shared_ptr< detail::ResultWrapper > pimpl)
inlineexplicit

Definition at line 602 of file result_set.hpp.

Member Function Documentation

◆ AsContainer() [1/2]

template<typename Container >
Container storages::postgres::ResultSet::AsContainer ( ) const

Extract data into a container. For more information see psql_typed_results.

Definition at line 937 of file result_set.hpp.

◆ AsContainer() [2/2]

template<typename Container >
Container storages::postgres::ResultSet::AsContainer ( RowTag ) const

Definition at line 956 of file result_set.hpp.

◆ AsOptionalSingleRow() [1/3]

template<typename T >
std::optional< T > storages::postgres::ResultSet::AsOptionalSingleRow ( ) const

Extract first row into user type.

Returns
A single row result set if non empty result was returned, empty std::optional otherwise
Exceptions
exceptionwhen result set size > 1

Definition at line 998 of file result_set.hpp.

◆ AsOptionalSingleRow() [2/3]

template<typename T >
std::optional< T > storages::postgres::ResultSet::AsOptionalSingleRow ( FieldTag ) const

Definition at line 1008 of file result_set.hpp.

◆ AsOptionalSingleRow() [3/3]

template<typename T >
std::optional< T > storages::postgres::ResultSet::AsOptionalSingleRow ( RowTag ) const

Definition at line 1003 of file result_set.hpp.

◆ AsSetOf() [1/3]

template<typename T >
auto storages::postgres::ResultSet::AsSetOf ( ) const

Get a wrapper for iterating over a set of typed results. For more information see psql_typed_results.

Definition at line 913 of file result_set.hpp.

◆ AsSetOf() [2/3]

template<typename T >
auto storages::postgres::ResultSet::AsSetOf ( FieldTag ) const

Definition at line 926 of file result_set.hpp.

◆ AsSetOf() [3/3]

template<typename T >
auto storages::postgres::ResultSet::AsSetOf ( RowTag ) const

Definition at line 918 of file result_set.hpp.

◆ AsSingleRow() [1/3]

template<typename T >
auto storages::postgres::ResultSet::AsSingleRow ( ) const

Extract first row into user type. A single row result set is expected, will throw an exception when result set size != 1.

Examples
samples/digest_auth_service/auth_digest.cpp, and samples/postgres_service/postgres_service.cpp.

Definition at line 975 of file result_set.hpp.

◆ AsSingleRow() [2/3]

template<typename T >
auto storages::postgres::ResultSet::AsSingleRow ( FieldTag ) const

Definition at line 989 of file result_set.hpp.

◆ AsSingleRow() [3/3]

template<typename T >
auto storages::postgres::ResultSet::AsSingleRow ( RowTag ) const

Definition at line 980 of file result_set.hpp.

◆ begin()

const_iterator storages::postgres::ResultSet::begin ( ) const &
inline

Definition at line 616 of file result_set.hpp.

◆ end()

const_iterator storages::postgres::ResultSet::end ( ) const &
inline

Definition at line 618 of file result_set.hpp.

◆ GetRowDescription()

RowDescription storages::postgres::ResultSet::GetRowDescription ( ) const &
inline

Definition at line 656 of file result_set.hpp.

◆ IsEmpty()

bool storages::postgres::ResultSet::IsEmpty ( ) const
inline

◆ operator[]()

reference storages::postgres::ResultSet::operator[] ( size_type index) const &

Access a row by index.

Exceptions
RowIndexOutOfBoundsif index is out of bounds

◆ rbegin()

const_reverse_iterator storages::postgres::ResultSet::rbegin ( ) const &
inline

Definition at line 629 of file result_set.hpp.

◆ rend()

const_reverse_iterator storages::postgres::ResultSet::rend ( ) const &
inline

Definition at line 631 of file result_set.hpp.

Friends And Related Symbol Documentation

◆ ConnectionImpl

friend class ConnectionImpl
friend

Definition at line 707 of file result_set.hpp.

◆ TypedResultSet

template<typename T , typename Tag >
friend class TypedResultSet
friend

Definition at line 706 of file result_set.hpp.

Member Data Documentation

◆ npos

constexpr size_type storages::postgres::ResultSet::npos = std::numeric_limits<size_type>::max()
staticconstexpr

Definition at line 590 of file result_set.hpp.


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