Lightweight 0.20251201.0
Loading...
Searching...
No Matches
Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived, QueryOptions > Class Template Reference

#include <QueryBuilders.hpp>

Inherits SqlBasicSelectQueryBuilder< Derived >.

Public Member Functions

bool Exist ()
 
size_t Count ()
 Executes a SELECT COUNT query and returns the number of records found.
 
std::vector< Record > All ()
 Executes a SELECT query and returns all records found.
 
void Delete ()
 Executes a DELETE query.
 
template<auto Field>
requires std::is_member_object_pointer_v<decltype(Field)>
auto All () -> std::vector< ReferencedFieldTypeOf< Field > >
 Executes a SELECT query and returns all records found for the specified field.
 
template<auto... ReferencedFields>
requires (sizeof...(ReferencedFields) >= 2)
auto All () -> std::vector< Record >
 Executes a SELECT query and returns all records found for the specified field, only having the specified fields queried and populated.
 
std::optional< Record > First ()
 Executes a SELECT query for the first record found and returns it.
 
template<auto Field>
requires std::is_member_object_pointer_v<decltype(Field)>
auto First () -> std::optional< ReferencedFieldTypeOf< Field > >
 Executes the query to get a single scalar value from the first record found.
 
template<auto... ReferencedFields>
requires (sizeof...(ReferencedFields) >= 2)
auto First () -> std::optional< Record >
 Executes a SELECT query for the first record found and returns it with only the specified fields populated.
 
std::vector< Record > First (size_t n)
 Executes a SELECT query for the first n records found and returns them.
 
template<auto... ReferencedFields>
std::vector< Record > First (size_t n)
 
std::vector< Record > Range (size_t offset, size_t limit)
 Executes a SELECT query for a range of records and returns them.
 
template<auto... ReferencedFields>
std::vector< Record > Range (size_t offset, size_t limit)
 

Protected Member Functions

LIGHTWEIGHT_FORCE_INLINE SqlCoreDataMapperQueryBuilder (DataMapper &dm, std::string fields) noexcept
 

Detailed Description

template<typename Record, typename Derived, DataMapperOptions QueryOptions = {}>
class Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived, QueryOptions >

Main API for mapping records to C++ from the database using high level C++ syntax.

Definition at line 31 of file QueryBuilders.hpp.

Constructor & Destructor Documentation

◆ SqlCoreDataMapperQueryBuilder()

template<typename Record , typename Derived , DataMapperOptions QueryOptions>
Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived, QueryOptions >::SqlCoreDataMapperQueryBuilder ( DataMapper dm,
std::string  fields 
)
inlineexplicitprotectednoexcept

Definition at line 604 of file DataMapper.hpp.

Member Function Documentation

◆ Exist()

template<typename Record , typename Derived , DataMapperOptions QueryOptions>
bool Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived, QueryOptions >::Exist ( )

Executes a SELECT 1 ... query and returns true if a record exists We do not provide db specific syntax to check this but reuse the First() implementation

Definition at line 628 of file DataMapper.hpp.

References Lightweight::SqlStatement::Connection().

◆ Count()

template<typename Record , typename Derived , DataMapperOptions QueryOptions>
size_t Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived, QueryOptions >::Count ( )

Executes a SELECT COUNT query and returns the number of records found.

Definition at line 613 of file DataMapper.hpp.

References Lightweight::SqlStatement::Connection().

◆ All() [1/3]

template<typename Record , typename Derived , DataMapperOptions QueryOptions>
std::vector< Record > Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived, QueryOptions >::All ( )

Executes a SELECT query and returns all records found.

Definition at line 663 of file DataMapper.hpp.

References Lightweight::SqlStatement::Connection().

◆ Delete()

template<typename Record , typename Derived , DataMapperOptions QueryOptions>
void Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived, QueryOptions >::Delete ( )

Executes a DELETE query.

Definition at line 648 of file DataMapper.hpp.

References Lightweight::SqlStatement::Connection().

◆ All() [2/3]

template<typename Record , typename Derived , DataMapperOptions QueryOptions>
requires std::is_member_object_pointer_v<decltype(Field)>
template<auto... ReferencedFields>
requires std::is_member_object_pointer_v<decltype(Field)>
auto Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived, QueryOptions >::All ( ) -> std::vector<ReferencedFieldTypeOf<Field>>

Executes a SELECT query and returns all records found for the specified field.

Template Parameters
FieldThe field to select from the record, in the form of &Record::FieldName.
Returns
A vector of values of the type of the specified field.
auto dm = DataMapper {};
auto const ages = dm.Query<Person>()
.OrderBy(FieldNameOf<&Person::age>, SqlResultOrdering::ASCENDING)
.All<&Person::age>();
Main API for mapping records to and from the database using high level C++ syntax.
std::vector< Record > Query(SqlSelectQueryBuilder::ComposedQuery const &selectQuery, InputParameters &&... inputParameters)
Queries multiple records from the database, based on the given query.

Definition at line 700 of file DataMapper.hpp.

References Lightweight::SqlStatement::Connection(), Lightweight::SqlResultCursor::FetchRow(), and Lightweight::SqlResultCursor::GetColumn().

◆ All() [3/3]

template<typename Record , typename Derived , DataMapperOptions QueryOptions = {}>
template<auto... ReferencedFields>
requires (sizeof...(ReferencedFields) >= 2)
auto Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived, QueryOptions >::All ( ) -> std::vector< Record >

Executes a SELECT query and returns all records found for the specified field, only having the specified fields queried and populated.

Template Parameters
ReferencedFieldsThe fields to select from the record, in the form of &Record::FieldName.
Returns
A vector of records with the given fields populated.
auto dm = DataMapper {};
auto const ages = dm.Query<Person>()
.OrderBy(FieldNameOf<&Person::age>, SqlResultOrdering::ASCENDING)
.All<&Person::name, &Person::age>();

◆ First() [1/5]

template<typename Record , typename Derived , DataMapperOptions QueryOptions>
std::optional< Record > Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived, QueryOptions >::First ( )

Executes a SELECT query for the first record found and returns it.

Definition at line 779 of file DataMapper.hpp.

References Lightweight::SqlStatement::Connection().

◆ First() [2/5]

template<typename Record , typename Derived , DataMapperOptions QueryOptions>
requires std::is_member_object_pointer_v<decltype(Field)>
template<auto... ReferencedFields>
requires std::is_member_object_pointer_v<decltype(Field)>
auto Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived, QueryOptions >::First ( ) -> std::optional<ReferencedFieldTypeOf<Field>>

Executes the query to get a single scalar value from the first record found.

Template Parameters
FieldThe field to select from the record, in the form of &Record::FieldName.
Returns
an optional value of the type of the field, or an empty optional if no record was found.

Definition at line 807 of file DataMapper.hpp.

References Lightweight::SqlStatement::Connection().

◆ First() [3/5]

template<typename Record , typename Derived , DataMapperOptions QueryOptions = {}>
template<auto... ReferencedFields>
requires (sizeof...(ReferencedFields) >= 2)
auto Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived, QueryOptions >::First ( ) -> std::optional< Record >

Executes a SELECT query for the first record found and returns it with only the specified fields populated.

Template Parameters
ReferencedFieldsThe fields to select from the record, in the form of &Record::FieldName.
Returns
an optional record with only the specified fields populated, or an empty optional if no record was found.

◆ First() [4/5]

template<typename Record , typename Derived , DataMapperOptions QueryOptions>
std::vector< Record > Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived, QueryOptions >::First ( size_t  n)

Executes a SELECT query for the first n records found and returns them.

Definition at line 865 of file DataMapper.hpp.

References Lightweight::SqlStatement::Connection().

◆ First() [5/5]

template<typename Record , typename Derived , DataMapperOptions QueryOptions>
template<auto... ReferencedFields>
std::vector< Record > Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived, QueryOptions >::First ( size_t  n)

Definition at line 971 of file DataMapper.hpp.

◆ Range() [1/2]

template<typename Record , typename Derived , DataMapperOptions QueryOptions>
std::vector< Record > Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived, QueryOptions >::Range ( size_t  offset,
size_t  limit 
)

Executes a SELECT query for a range of records and returns them.

Definition at line 889 of file DataMapper.hpp.

References Lightweight::SqlStatement::Connection(), and Lightweight::FieldNameAt.

◆ Range() [2/2]

template<typename Record , typename Derived , DataMapperOptions QueryOptions>
template<auto... ReferencedFields>
std::vector< Record > Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived, QueryOptions >::Range ( size_t  offset,
size_t  limit 
)

Definition at line 918 of file DataMapper.hpp.


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