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

#include <QueryBuilders.hpp>

Inherits SqlBasicSelectQueryBuilder< Derived >.

Public Member Functions

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.
 
template<auto 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>
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 (SqlStatement &stmt, std::string fields) noexcept
 

Detailed Description

template<typename Record, typename Derived>
class Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived >

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

Definition at line 199 of file QueryBuilders.hpp.

Constructor & Destructor Documentation

◆ SqlCoreDataMapperQueryBuilder()

template<typename Record , typename Derived >
LIGHTWEIGHT_FORCE_INLINE Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived >::SqlCoreDataMapperQueryBuilder ( SqlStatement stmt,
std::string  fields 
)
inlineexplicitprotectednoexcept

Definition at line 220 of file QueryBuilders.hpp.

Member Function Documentation

◆ Count()

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

◆ All() [1/3]

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

◆ All() [2/3]

template<typename Record , typename Derived >
template<auto Field>
auto Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived >::All ( ) -> std::vector<ReferencedFieldTypeOf<Field>>
inline

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 271 of file QueryBuilders.hpp.

References Lightweight::SqlStatement::Connection(), Lightweight::SqlStatement::ExecuteDirect(), Lightweight::SqlResultCursor::FetchRow(), Lightweight::SqlResultCursor::GetColumn(), Lightweight::SqlStatement::GetResultCursor(), Lightweight::SqlQueryFormatter::SelectAll(), and Lightweight::SqlConnection::ServerType().

◆ All() [3/3]

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

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>();

Definition at line 320 of file QueryBuilders.hpp.

References Lightweight::SqlResultCursor::BindOutputColumns(), and Lightweight::SqlResultCursor::FetchRow().

◆ First() [1/5]

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

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

Definition at line 360 of file QueryBuilders.hpp.

◆ First() [2/5]

template<typename Record , typename Derived >
template<auto Field>
auto Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived >::First ( ) -> std::optional<ReferencedFieldTypeOf<Field>>
inline

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 381 of file QueryBuilders.hpp.

◆ First() [3/5]

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

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.

Definition at line 404 of file QueryBuilders.hpp.

References Lightweight::SqlResultCursor::BindOutputColumns(), and Lightweight::SqlResultCursor::FetchRow().

◆ First() [4/5]

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

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

Definition at line 438 of file QueryBuilders.hpp.

◆ First() [5/5]

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

Definition at line 455 of file QueryBuilders.hpp.

◆ Range() [1/2]

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

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

Definition at line 495 of file QueryBuilders.hpp.

References Lightweight::FieldNameAt.

◆ Range() [2/2]

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

Definition at line 517 of file QueryBuilders.hpp.


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