relx 0.1.0
A Modern C++23 Type-Safe SQL Query Builder
Loading...
Searching...
No Matches
relx::result::ResultSet Class Reference

Represents the result set from a database query. More...

#include <relx/results/result.hpp>

Public Member Functions

 ResultSet ()=default
 Default constructor.
 
 ResultSet (std::vector< Row > rows, std::vector< std::string > column_names={})
 Constructs a result set with rows and column names.
 
size_t size () const
 Get the number of rows in the result set.
 
bool empty () const
 Check if the result set is empty.
 
const Rowat (size_t index) const
 Get a row by index.
 
const Rowoperator[] (size_t index) const
 Access a row by index using the subscript operator.
 
size_t column_count () const
 Get the number of columns in the result set.
 
ResultProcessingResult< std::string > column_name (size_t index) const
 Get the name of a column by index.
 
const std::vector< std::string > & column_names () const
 Get the column names.
 
auto begin () const
 Get an iterator to the beginning of the rows.
 
auto end () const
 Get an iterator to the end of the rows.
 
template<typename T >
std::vector< T > transform (std::function< ResultProcessingResult< T >(const Row &)> mapper) const
 Transform each row into an object of type T.
 
template<typename... Types>
auto as () const
 Helper for structured binding with explicit types.
 
template<typename... Types>
auto as (const std::array< size_t, sizeof...(Types)> &indices) const
 Helper for structured binding with explicit types and column indices.
 
template<typename... Types>
auto as (const std::array< std::string, sizeof...(Types)> &column_names) const
 Helper for structured binding with explicit types and column names.
 
template<typename Table , typename P1 , typename... Ps>
requires schema::TableConcept<Table>
auto with_schema (P1 mp1, Ps... mps) const
 Creates a structured binding view using table schema information.
 
template<typename Table , typename P1 , typename... Ps>
requires schema::TableConcept<std::remove_reference_t<Table>>
auto with_schema (const Table &, P1 mp1, Ps... mps) const
 Creates a structured binding view using table schema information.
 
std::string to_string () const
 

Detailed Description

Represents the result set from a database query.

Definition at line 608 of file result.hpp.

Constructor & Destructor Documentation

◆ ResultSet() [1/2]

relx::result::ResultSet::ResultSet ( )
default

Default constructor.

◆ ResultSet() [2/2]

relx::result::ResultSet::ResultSet ( std::vector< Row rows,
std::vector< std::string >  column_names = {} 
)
inline

Constructs a result set with rows and column names.

Definition at line 614 of file result.hpp.

Member Function Documentation

◆ as() [1/3]

template<typename... Types>
auto relx::result::ResultSet::as ( ) const
inline

Helper for structured binding with explicit types.

Template Parameters
TypesThe C++ types for each column
Returns
A helper object that supports structured binding

Definition at line 684 of file result.hpp.

◆ as() [2/3]

template<typename... Types>
auto relx::result::ResultSet::as ( const std::array< size_t, sizeof...(Types)> &  indices) const
inline

Helper for structured binding with explicit types and column indices.

Template Parameters
TypesThe C++ types for each column
Parameters
indicesArray of column indices to use for structured binding
Returns
A helper object that supports structured binding

Definition at line 698 of file result.hpp.

◆ as() [3/3]

template<typename... Types>
auto relx::result::ResultSet::as ( const std::array< std::string, sizeof...(Types)> &  column_names) const
inline

Helper for structured binding with explicit types and column names.

Template Parameters
TypesThe C++ types for each column
Parameters
column_namesArray of column names to use for structured binding
Returns
A helper object that supports structured binding

Definition at line 707 of file result.hpp.

◆ at()

const Row & relx::result::ResultSet::at ( size_t  index) const
inline

Get a row by index.

Parameters
indexThe zero-based index of the row
Returns
The row at the specified index

Definition at line 628 of file result.hpp.

◆ begin()

auto relx::result::ResultSet::begin ( ) const
inline

Get an iterator to the beginning of the rows.

Returns
Iterator to the first row

Definition at line 655 of file result.hpp.

◆ column_count()

size_t relx::result::ResultSet::column_count ( ) const
inline

Get the number of columns in the result set.

Returns
The number of columns

Definition at line 637 of file result.hpp.

◆ column_name()

ResultProcessingResult< std::string > relx::result::ResultSet::column_name ( size_t  index) const
inline

Get the name of a column by index.

Parameters
indexThe zero-based index of the column
Returns
The name of the column or an error

Definition at line 642 of file result.hpp.

◆ column_names()

const std::vector< std::string > & relx::result::ResultSet::column_names ( ) const
inline

Get the column names.

Returns
The column names

Definition at line 651 of file result.hpp.

◆ empty()

bool relx::result::ResultSet::empty ( ) const
inline

Check if the result set is empty.

Returns
True if there are no rows

Definition at line 623 of file result.hpp.

◆ end()

auto relx::result::ResultSet::end ( ) const
inline

Get an iterator to the end of the rows.

Returns
Iterator past the last row

Definition at line 659 of file result.hpp.

◆ operator[]()

const Row & relx::result::ResultSet::operator[] ( size_t  index) const
inline

Access a row by index using the subscript operator.

Parameters
indexThe zero-based index of the row
Returns
The row at the specified index

Definition at line 633 of file result.hpp.

◆ size()

size_t relx::result::ResultSet::size ( ) const
inline

Get the number of rows in the result set.

Returns
The number of rows

Definition at line 619 of file result.hpp.

◆ to_string()

std::string relx::result::ResultSet::to_string ( ) const
inline

Definition at line 792 of file result.hpp.

◆ transform()

template<typename T >
std::vector< T > relx::result::ResultSet::transform ( std::function< ResultProcessingResult< T >(const Row &)>  mapper) const
inline

Transform each row into an object of type T.

Template Parameters
TThe target object type
Parameters
mapperFunction that maps a Row to an object of type T
Returns
A vector of transformed objects

Definition at line 666 of file result.hpp.

◆ with_schema() [1/2]

template<typename Table , typename P1 , typename... Ps>
requires schema::TableConcept<std::remove_reference_t<Table>>
auto relx::result::ResultSet::with_schema ( const Table &  ,
P1  mp1,
Ps...  mps 
) const
inline

Creates a structured binding view using table schema information.

This overload enables structured binding with a complete table schema, making it easier to use with a pre-existing table instance.

Template Parameters
TableThe table schema type
P1,P2,...Member pointer types to column members
Parameters
tableThe table instance to extract schema from
mp1,mp2,...Column member pointers to bind to
Returns
A view that supports structured binding iteration

Example:

Users users;
for (const auto& [id, name, email] : results.with_schema(users, &Users::id, &Users::name,
&Users::email)) {
// Use the values with proper types
}
auto with_schema(P1 mp1, Ps... mps) const
Creates a structured binding view using table schema information.
Definition result.hpp:750

Definition at line 788 of file result.hpp.

◆ with_schema() [2/2]

template<typename Table , typename P1 , typename... Ps>
requires schema::TableConcept<Table>
auto relx::result::ResultSet::with_schema ( P1  mp1,
Ps...  mps 
) const
inline

Creates a structured binding view using table schema information.

This method enables structured binding with the table's schema, eliminating the need to manually specify column names or indices.

Template Parameters
TableThe table schema type (must satisfy TableType concept)
P1,P2,...Member pointer types to column members
Parameters
mp1,mp2,...Column member pointers to bind to
Returns
A view that supports structured binding iteration

Example:

Users users;
for (const auto& [id, name, email] : results.with_schema<Users>(&Users::id, &Users::name,
&Users::email)) {
// Use the values with proper types
}

Definition at line 750 of file result.hpp.


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