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

Parameters of a described type: the common description of objects ( anch::Mapping<T> , anch-utils) registered for SQL. More...

#include <fields.hpp>

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

Classes

struct  Field
 Field which has a value. More...

Public Member Functions

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

Static Public Member Functions

static const FieldsMapper< T > & instance ()

Detailed Description

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

Parameters of a described type: the common description of objects ( anch::Mapping<T> , anch-utils) registered for SQL.

Each field which has a value (member or getter) is a parameter named as the field: fields which are only written (setter) are ignored. Fields values have to be bindable ( Bindable : integers, floating point numbers, booleans, strings, dates ( anch::date::Date , anch::date::DateTime , anch::date::Time , std::chrono::sys_time ), anch::UUID (with ANCH_UUID ), std::optional and lists of them): a field of another type 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< typename FieldsMapper< T >::Field > & anch::sql::FieldsMapper< T >::fields ( ) const
noexcept

Fields getter

Returns
the fields which have a value, in registration order

◆ find()

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

Find field

Parameters
namethe field name
Returns
the field, nullptr when T has no such field (or when it is only written)

◆ instance()

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

Mapper of T (built once)

Returns
the mapper

◆ registerField() [1/4]

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

Register field by setter: ignored (the field has no value)

Template Parameters
Pthe field type
Cthe constraints types
Returns
this

◆ registerField() [2/4]

template<anch::Described T>
template<typename P, typename... C>
FieldsMapper< T > & anch::sql::FieldsMapper< 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>
FieldsMapper< T > & anch::sql::FieldsMapper< T >::registerField ( const std::string & name,
std::function< P(const T &)> getter,
C && ... )

Register field by getter

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

◆ registerField() [4/4]

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

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

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

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