AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
anch::sql::RowMapper< T > Class Template Reference

Result columns of a described type: the common description of objects ( anch::Mapping<T> , anch-utils) registered to read result rows. More...

#include <rows.hpp>

Collaboration diagram for anch::sql::RowMapper< T >:

Classes

struct  Field
 Field which can be written. More...

Public Member Functions

const Field * find (std::string_view column) const noexcept
const std::vector< Field > & fields () const noexcept
template<typename P, typename... C>
RowMapper< T > & registerField (const std::string &name, P T::*member, C &&...)
template<typename P, typename... C>
RowMapper< T > & registerField (const std::string &, std::function< P(const T &)>, C &&...)
template<typename P, typename... C>
RowMapper< T > & registerField (const std::string &name, std::function< void(T &, const P &)> setter, C &&...)
template<typename P, typename... C>
RowMapper< T > & registerField (const std::string &name, std::function< P(const T &)>, std::function< void(T &, const P &)> setter, C &&...)

Static Public Member Functions

static const RowMapper< T > & instance ()

Detailed Description

template<anch::Described T>
class anch::sql::RowMapper< T >

Result columns of a described type: the common description of objects ( anch::Mapping<T> , anch-utils) registered to read result rows.

Each field which can be written (member or setter) is filled with the column of the same name (ASCII case is ignored: PostgreSQL gives unquoted names in lowercase) ; fields which are only read (getter) are ignored. Fields values have to be Readable : a field of another type (nested object, collection, ...) is refused at compile time. Constraints are not checked (validate objects with anch::val::validate ).

Template Parameters
Tthe described type
Author
Vincent Lachenal
Since
0.3

Member Function Documentation

◆ fields()

template<anch::Described T>
const std::vector< Field > & anch::sql::RowMapper< T >::fields ( ) const
noexcept

Fields getter

Returns
the fields which can be written, in registration order

◆ find()

template<anch::Described T>
const Field * anch::sql::RowMapper< T >::find ( std::string_view column) const
noexcept

Find field of a column: field of the same name, or of the same name ignoring ASCII case

Parameters
columnthe column name
Returns
the field, nullptr when T has no such field (or when it is only read)

◆ instance()

template<anch::Described T>
const RowMapper< T > & anch::sql::RowMapper< T >::instance ( )
static

Mapper of T (built once)

Returns
the mapper

◆ registerField() [1/4]

template<anch::Described T>
template<typename P, typename... C>
RowMapper< T > & anch::sql::RowMapper< T >::registerField ( const std::string & ,
std::function< P(const T &)> ,
C && ... )

Register field by getter: ignored (the field can not be written)

Template Parameters
Pthe field type
Cthe constraints types
Returns
this
Here is the call graph for this function:

◆ registerField() [2/4]

template<anch::Described T>
template<typename P, typename... C>
RowMapper< T > & anch::sql::RowMapper< T >::registerField ( const std::string & name,
P T::* member,
C && ... )

Register field by member

Template Parameters
Pthe field type
Cthe constraints types
Parameters
namethe field name
memberthe member
Returns
this
Here is the call graph for this function:

◆ registerField() [3/4]

template<anch::Described T>
template<typename P, typename... C>
RowMapper< T > & anch::sql::RowMapper< T >::registerField ( const std::string & name,
std::function< P(const T &)> ,
std::function< void(T &, const P &)> setter,
C && ... )

Register field by getter and setter (the setter writes the value)

Template Parameters
Pthe field type
Cthe constraints types
Parameters
namethe field name
setterthe setter
Returns
this
Here is the call graph for this function:

◆ registerField() [4/4]

template<anch::Described T>
template<typename P, typename... C>
RowMapper< T > & anch::sql::RowMapper< T >::registerField ( const std::string & name,
std::function< void(T &, const P &)> setter,
C && ... )

Register field by setter

Template Parameters
Pthe field type
Cthe constraints types
Parameters
namethe field name
setterthe setter
Returns
this
Here is the call graph for this function:

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