5#include "../SqlConnection.hpp"
6#include "../SqlQueryFormatter.hpp"
7#include "../SqlStatement.hpp"
9#include "BelongsTo.hpp"
30template <
typename Record,
typename Derived, DataMapperOptions QueryOptions = {}>
38 std::vector<SqlVariant> _boundInputs;
42 LIGHTWEIGHT_FORCE_INLINE SqlSearchCondition& SearchCondition()
noexcept
44 return this->_query.searchCondition;
47 [[nodiscard]] LIGHTWEIGHT_FORCE_INLINE
SqlQueryFormatter const& Formatter()
const noexcept
59 [[nodiscard]]
bool Exist();
62 [[nodiscard]]
size_t Count();
65 [[nodiscard]] std::vector<Record> All();
83#if defined(LIGHTWEIGHT_CXX26_REFLECTION)
84 requires(is_aggregate_type(parent_of(
Field)))
86 requires std::is_member_object_pointer_v<
decltype(
Field)>
88 [[nodiscard]]
auto All() -> std::vector<ReferencedFieldTypeOf<Field>>;
103 template <
auto... ReferencedFields>
104 requires(
sizeof...(ReferencedFields) >= 2)
105 [[nodiscard]]
auto All() -> std::vector<Record>;
108 [[nodiscard]] std::optional<Record> First();
115 template <auto Field>
116#if defined(LIGHTWEIGHT_CXX26_REFLECTION)
117 requires(is_aggregate_type(parent_of(
Field)))
119 requires std::is_member_object_pointer_v<
decltype(
Field)>
121 auto First() -> std::optional<ReferencedFieldTypeOf<Field>>;
128 template <
auto... ReferencedFields>
129 requires(
sizeof...(ReferencedFields) >= 2)
130 [[nodiscard]]
auto First() -> std::optional<Record>;
133 [[nodiscard]] std::vector<Record> First(
size_t n);
136 template <
auto... ReferencedFields>
137 [[nodiscard]] std::vector<Record> First(
size_t n);
140 [[nodiscard]] std::vector<Record> Range(
size_t offset,
size_t limit);
143 template <
auto... ReferencedFields>
144 [[nodiscard]] std::vector<Record> Range(
size_t offset,
size_t limit);
150template <
typename Record, DataMapperOptions QueryOptions>
160 dm, std::move(fields)
165 static void ReadResults(SqlServerType sqlServerType,
SqlResultCursor reader, std::vector<Record>* records);
166 static void ReadResult(SqlServerType sqlServerType,
SqlResultCursor reader, std::optional<Record>* optionalRecord);
174template <
typename FirstRecord,
typename SecondRecord, DataMapperOptions QueryOptions>
177 SqlAllFieldsQueryBuilder<std::tuple<FirstRecord, SecondRecord>, QueryOptions>,
181 using RecordType = std::tuple<FirstRecord, SecondRecord>;
187 dm, std::move(fields)
192 static void ReadResults(SqlServerType sqlServerType, SqlResultCursor reader, std::vector<RecordType>* records);
Main API for mapping records to and from the database using high level C++ syntax.
Represents a query builder that retrieves all fields of a record.
auto First() -> std::optional< Record >
Executes a SELECT query for the first record found and returns it with only the specified fields popu...
auto All() -> std::vector< Record >
Executes a SELECT query and returns all records found for the specified field, only having the specif...
API for reading an SQL query result set.
bool loadRelations
Whether to automatically load relations when querying records.
Represents a single column in a table.