|
Lightweight 0.20260921.0
|
#include <QueryBuilders.hpp>
Public Member Functions | |
| auto | Exist () |
| auto | Count () |
| auto | All () |
| Executes a SELECT query and returns all records found. | |
| template<auto... RelationPath> requires DataMapperRecord<Record> && (sizeof...(RelationPath) >= 1) | |
| Derived & | With () |
| Eagerly loads the given relation for every record the query returns, in a bounded number of queries instead of one per record. | |
| auto | Delete () |
| Executes a DELETE query. | |
| template<auto Field> requires std::is_member_object_pointer_v<decltype(Field)> | |
| auto | All () |
| Executes a SELECT query and returns all records found for the specified field. | |
| template<auto... ReferencedFields> requires (sizeof...(ReferencedFields) >= 2) | |
| auto | All () |
| Executes a SELECT query and returns all records found for the specified field, only having the specified fields queried and populated. | |
| auto | 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 () |
| Executes the query to get a single scalar value from the first record found. | |
| template<auto... ReferencedFields> requires (sizeof...(ReferencedFields) >= 2) | |
| auto | First () |
| Executes a SELECT query for the first record found and returns it with only the specified fields populated. | |
| auto | First (size_t n) |
| Executes a SELECT query for the first n records found and returns them. | |
| template<auto... ReferencedFields> | |
| auto | First (size_t n) |
| Executes a SELECT query for the first n records with only the specified fields populated. | |
| auto | Range (size_t offset, size_t limit) |
| Executes a SELECT query for a range of records and returns them. | |
| template<auto... ReferencedFields> | |
| auto | Range (size_t offset, size_t limit) |
| Executes a SELECT query for a range of records with only the specified fields populated. | |
Protected Member Functions | |
| LIGHTWEIGHT_FORCE_INLINE | SqlCoreDataMapperQueryBuilder (DataMapper &dm, std::string fields) noexcept |
| Constructs a query builder with the given data mapper and field list. | |
Main API for mapping records to C++ from the database using high level C++ syntax.
Definition at line 69 of file QueryBuilders.hpp.
|
inlineexplicitprotectednoexcept |
Constructs a query builder with the given data mapper and field list.
Definition at line 1211 of file DataMapper.hpp.
|
inline |
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 112 of file QueryBuilders.hpp.
|
inline |
Executes a SELECT COUNT query and returns the number of records found.
A preceding GroupBy is honored, making the query count per group. Since only a single value is returned, the caller receives the count of one arbitrary group: the emitted SELECT COUNT query carries no ORDER BY (a preceding OrderBy does not apply to it), so which group's count is read back is unspecified and may differ between database systems and between runs.
Definition at line 124 of file QueryBuilders.hpp.
|
inline |
Executes a SELECT query and returns all records found.
Definition at line 130 of file QueryBuilders.hpp.
| Derived & Lightweight::SqlCoreDataMapperQueryBuilder< Record, Derived, QueryOptions >::With | ( | ) |
Eagerly loads the given relation for every record the query returns, in a bounded number of queries instead of one per record.
Touching a relation on a query result normally loads it on demand, one query per record - the N+1 problem. With<>() instead resolves the relation for the whole result set after it has been materialized: the keys are collected, the related rows are fetched with WHERE ... IN (...) (chunked, see SqlQueryFormatter::MaxInPredicateValues), and the rows are distributed to the records in memory.
Call it once per relation to load; the calls chain.
Naming several relations forms a path: the first is resolved for the result set, the records it loaded are then gathered and the next relation resolved for all of them at once. A path of any length still costs a constant number of queries per level, never one per record - which is what a nested BelongsTo needs, since each record holds its own copy of the target and touching that copy's own relation would otherwise be an N+1 one level down.
| RelationPath | One or more relations, in the form of &Record::FieldName. The first must be a member of the queried record, each subsequent one a member of the preceding relation's target. Supported for BelongsTo and HasMany; naming any other member is a compile error. |
With<>() with DataMapperOptions { .loadRelations = false } therefore makes any unrequested relation throw SqlRequireLoadedError on access rather than quietly issuing a query. To eagerly load everything instead of naming paths, see DataMapperOptions::eagerLoadDepth.Definition at line 1239 of file DataMapper.hpp.
|
inline |
Executes a DELETE query.
Definition at line 180 of file QueryBuilders.hpp.
|
inline |
Executes a SELECT query and returns all records found for the specified field.
| Field | The field to select from the record, in the form of &Record::FieldName. |
Definition at line 203 of file QueryBuilders.hpp.
|
inline |
Executes a SELECT query and returns all records found for the specified field, only having the specified fields queried and populated.
| ReferencedFields | The fields to select from the record, in the form of &Record::FieldName. |
Definition at line 223 of file QueryBuilders.hpp.
|
inline |
Executes a SELECT query for the first record found and returns it.
Definition at line 229 of file QueryBuilders.hpp.
|
inline |
Executes the query to get a single scalar value from the first record found.
| Field | The field to select from the record, in the form of &Record::FieldName. |
Definition at line 245 of file QueryBuilders.hpp.
|
inline |
Executes a SELECT query for the first record found and returns it with only the specified fields populated.
| ReferencedFields | The fields to select from the record, in the form of &Record::FieldName. |
Definition at line 257 of file QueryBuilders.hpp.
|
inline |
Executes a SELECT query for the first n records found and returns them.
Definition at line 263 of file QueryBuilders.hpp.
|
inline |
Executes a SELECT query for the first n records with only the specified fields populated.
Definition at line 270 of file QueryBuilders.hpp.
|
inline |
Executes a SELECT query for a range of records and returns them.
Definition at line 276 of file QueryBuilders.hpp.
|
inline |
Executes a SELECT query for a range of records with only the specified fields populated.
Definition at line 283 of file QueryBuilders.hpp.