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

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

Detailed Description

Data row in a result set This class is a mere accessor to underlying result set data buffer, must not be used outside of result set life scope.

Mimics field container

Definition at line 413 of file result_set.hpp.

Public Member Functions

Field container interface
size_type Size () const
 Number of fields.
 
Forward iteration
const_iterator cbegin () const
 
const_iterator begin () const
 
const_iterator cend () const
 
const_iterator end () const
 
Reverse iteration
const_reverse_iterator crbegin () const
 
const_reverse_iterator rbegin () const
 
const_reverse_iterator crend () const
 
const_reverse_iterator rend () const
 
reference operator[] (size_type index) const
 Field access by index.
 
reference operator[] (const std::string &name) const
 Field access field by name.
 

Field container concept

using size_type = std::size_t
 
using const_iterator = ConstFieldIterator
 
using const_reverse_iterator = ReverseConstFieldIterator
 
using value_type = Field
 
using reference = Field
 
using pointer = const_iterator
 
size_type RowIndex () const
 
RowDescription GetDescription () const
 

Access to row's data

class ResultSet
 
template<typename T >
void To (T &&val) const
 
template<typename T >
void To (T &&val, RowTag) const
 
template<typename T >
void To (T &&val, FieldTag) const
 
template<typename... T>
void To (T &&... val) const
 Read fields into variables in order of their appearance in the row.
 
template<typename T , typename... Y>
auto As () const
 Parse values from the row and return the result.
 
template<typename T >
As (RowTag) const
 Returns T initialized with values of the row.
 
template<typename T >
As (FieldTag) const
 Returns T initialized with a single column value of the row.
 
template<typename... T>
void To (const std::initializer_list< std::string > &names, T &&... val) const
 Read fields into variables in order of their names in the first argument.
 
template<typename... T>
std::tuple< T... > As (const std::initializer_list< std::string > &names) const
 
template<typename... T>
void To (const std::initializer_list< size_type > &indexes, T &&... val) const
 
template<typename... T>
std::tuple< T... > As (const std::initializer_list< size_type > &indexes) const
 
size_type IndexOfName (const std::string &) const
 
FieldView GetFieldView (size_type index) const
 
 Row (detail::ResultWrapperPtr res, size_type row)
 

Iteration support

bool IsValid () const
 
int Compare (const Row &rhs) const
 
std::ptrdiff_t Distance (const Row &rhs) const
 
RowAdvance (std::ptrdiff_t)
 

Member Typedef Documentation

◆ const_iterator

◆ const_reverse_iterator

◆ pointer

◆ reference

Definition at line 422 of file result_set.hpp.

◆ size_type

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

Definition at line 417 of file result_set.hpp.

◆ value_type

Definition at line 421 of file result_set.hpp.

Constructor & Destructor Documentation

◆ Row()

storages::postgres::Row::Row ( detail::ResultWrapperPtr res,
size_type row )
inlineprotected

Definition at line 550 of file result_set.hpp.

Member Function Documentation

◆ As() [1/5]

template<typename T , typename... Y>
auto storages::postgres::Row::As ( ) const

Parse values from the row and return the result.

If there are more than one type arguments to the function, it will return a tuple of those types.

If there is a single type argument to the function, it will read the first and the only column of the row or the whole row to the row type (depending on C++ to PosgreSQL mapping presence) and return plain value of this type.

See also
To(T&&)

Definition at line 878 of file result_set.hpp.

◆ As() [2/5]

template<typename... T>
std::tuple< T... > storages::postgres::Row::As ( const std::initializer_list< size_type > & indexes) const

Definition at line 917 of file result_set.hpp.

◆ As() [3/5]

template<typename... T>
std::tuple< T... > storages::postgres::Row::As ( const std::initializer_list< std::string > & names) const

Definition at line 898 of file result_set.hpp.

◆ As() [4/5]

template<typename T >
T storages::postgres::Row::As ( FieldTag ) const
inline

Returns T initialized with a single column value of the row.

auto result = GetConn()->Execute("select ROW($1, $2)", 42, 3.14);
using TupleType = std::tuple<int, double>;
auto tuple = result.AsSingleRow<TupleType>(storages::postgres::kFieldTag);
EXPECT_EQ(std::get<0>(tuple), 42);

Definition at line 521 of file result_set.hpp.

◆ As() [5/5]

template<typename T >
T storages::postgres::Row::As ( RowTag ) const
inline

Returns T initialized with values of the row.

const auto res = GetConn()->Execute("select $1, $2", 42, "foobar");
using TupleType = std::tuple<int, std::string>;
auto tuple = res.AsSingleRow<TupleType>(storages::postgres::kRowTag);
EXPECT_EQ(std::get<0>(tuple), 42);
EXPECT_EQ(std::get<1>(tuple), "foobar");

Definition at line 512 of file result_set.hpp.

◆ begin()

const_iterator storages::postgres::Row::begin ( ) const
inline

Definition at line 437 of file result_set.hpp.

◆ end()

const_iterator storages::postgres::Row::end ( ) const
inline

Definition at line 439 of file result_set.hpp.

◆ GetDescription()

RowDescription storages::postgres::Row::GetDescription ( ) const
inline

Definition at line 428 of file result_set.hpp.

◆ operator[]() [1/2]

reference storages::postgres::Row::operator[] ( const std::string & name) const

Field access field by name.

Exceptions
FieldNameDoesntExistif the result set doesn't contain such a field

◆ operator[]() [2/2]

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

Field access by index.

Exceptions
FieldIndexOutOfBoundsif index is out of bounds

◆ rbegin()

const_reverse_iterator storages::postgres::Row::rbegin ( ) const
inline

Definition at line 444 of file result_set.hpp.

◆ rend()

const_reverse_iterator storages::postgres::Row::rend ( ) const
inline

Definition at line 446 of file result_set.hpp.

◆ RowIndex()

size_type storages::postgres::Row::RowIndex ( ) const
inline

Definition at line 426 of file result_set.hpp.

◆ To() [1/6]

template<typename... T>
void storages::postgres::Row::To ( const std::initializer_list< size_type > & indexes,
T &&... val ) const

Read fields into variables in order of their indexes in the first argument

Definition at line 908 of file result_set.hpp.

◆ To() [2/6]

template<typename... T>
void storages::postgres::Row::To ( const std::initializer_list< std::string > & names,
T &&... val ) const

Read fields into variables in order of their names in the first argument.

Definition at line 889 of file result_set.hpp.

◆ To() [3/6]

template<typename... T>
void storages::postgres::Row::To ( T &&... val) const

Read fields into variables in order of their appearance in the row.

Definition at line 869 of file result_set.hpp.

◆ To() [4/6]

template<typename T >
void storages::postgres::Row::To ( T && val) const

Read the contents of the row to a user's row type or read the first column into the value.

If the user tries to read the first column into a variable, it must be the only column in the result set. If the result set contains more than one column, the function will throw NonSingleColumnResultSet. If the result set is OK to contain more than one columns, the first column value should be accessed via row[0].To/As.

If the type is a 'row' type, the function will read the fields of the row into the type's data members.

If the type can be treated as both a row type and a composite type (the type is mapped to a PostgreSQL type), the function will treat the type as a type for the first (and the only) column.

To read the all fields of the row as a row type, the To(T&&, RowTag) should be used.

Definition at line 829 of file result_set.hpp.

◆ To() [5/6]

template<typename T >
void storages::postgres::Row::To ( T && val,
FieldTag  ) const

Function to disambiguate reading the first column to a user's composite type (PostgreSQL composite type in the row initializes user's type). The same as calling To(T&& val) for a T mapped to a PostgreSQL type.

Definition at line 854 of file result_set.hpp.

◆ To() [6/6]

template<typename T >
void storages::postgres::Row::To ( T && val,
RowTag  ) const

Function to disambiguate reading the row to a user's row type (values of the row initialize user's type data members)

Definition at line 834 of file result_set.hpp.

Friends And Related Symbol Documentation

◆ ResultSet

friend class ResultSet
friend

Definition at line 546 of file result_set.hpp.


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