8#include <reflection-cpp/reflection.hpp>
16template <
size_t... Ints>
23struct IsSqlElements: std::false_type
27template <
size_t... Ints>
28struct IsSqlElements<
SqlElements<Ints...>>: std::true_type
35concept NotSqlElements = !detail::IsSqlElements<T>::value;
43template <
typename Record>
49template <std::
size_t I,
typename Record>
50constexpr std::optional<size_t> FindPrimaryKeyIndex()
53 if constexpr (I < Reflection::CountMembers<Record>)
55 if constexpr (IsPrimaryKey<Reflection::MemberTypeOf<I, Record>>)
58 return FindPrimaryKeyIndex<I + 1, Record>();
66template <
typename Record>
67constexpr size_t RecordPrimaryKeyIndex =
68 detail::FindPrimaryKeyIndex<0, Record>().value_or((std::numeric_limits<size_t>::max)());
71template <
typename Record>
72decltype(
auto) RecordPrimaryKeyOf(Record&& record)
76 return Reflection::GetMemberAt<RecordPrimaryKeyIndex<std::remove_cvref_t<Record>>>(std::forward<Record>(record));
82template <
typename Record>
83struct RecordPrimaryKeyTypeHelper
88template <
typename Record>
89 requires(RecordPrimaryKeyIndex<Record> < Reflection::CountMembers<Record>)
90struct RecordPrimaryKeyTypeHelper<Record>
92 using type =
typename Reflection::MemberTypeOf<RecordPrimaryKeyIndex<Record>, Record>::ValueType;
98template <
typename Record>
99using RecordPrimaryKeyType =
typename details::RecordPrimaryKeyTypeHelper<Record>::type;
102template <
typename Record,
typename TargetMappable>
103void MapFromRecordFields(Record&& record, TargetMappable& target)
105 Reflection::EnumerateMembers(std::forward<Record>(record), [&]<std::size_t I>(
auto const& field) {
106 using MemberType = Reflection::MemberTypeOf<I, Record>;
107 static_assert(IsField<MemberType>,
"Record member must be a Field<> type");
108 static_assert(std::is_assignable_v<
decltype(target[I]),
decltype(field.Value())>,
109 "Target must support operator[] with the field type");
110 target[I] = field.Value();
Represents a record type that can be used with the DataMapper.
std::integer_sequence< size_t, Ints... > SqlElements
Represents a sequence of indexes that can be used alongside Query() to retrieve only part of the reco...