24inline constexpr bool alwaysFalse =
false;
27struct StaticOptionalTraits
29 inline static constexpr bool isOptional =
false;
33template <NullableAdaptable T>
34struct StaticOptionalTraits<T>
36 inline static constexpr bool isOptional =
true;
37 using Value =
typename NullableAdapter<T>::Value;
41using static_optional_value_t =
typename StaticOptionalTraits<std::remove_cv_t<T>>::Value;
44struct MemberPointerTraits;
46template <
typename Value,
typename Owner>
47struct MemberPointerTraits<Value Owner::*>
49 using OwnerType = Owner;
50 using ValueType = Value;
54using member_owner_t =
typename MemberPointerTraits<std::remove_cv_t<
decltype(Member)>>::OwnerType;
57using member_value_t =
typename MemberPointerTraits<std::remove_cv_t<
decltype(Member)>>::ValueType;
60[[nodiscard]]
consteval auto isPersistentColumnMember() noexcept ->
bool
70consteval decltype(
auto) reflectedMemberName()
72 return (reflectedMemberNameStorage<Member>);
75template <
typename Model, std::
size_t Index>
76consteval auto reflectedFieldName() -> std::string_view
79 return descriptors[Index].name;
82template <
typename Model,
auto Member, std::size_t... Indices>
83consteval auto memberExistsImpl(std::index_sequence<Indices...>) ->
bool
85 constexpr auto memberName = reflectedMemberName<Member>();
86 return ((
memberName.view().compare(reflectedFieldName<Model, Indices>()) == 0) || ...);
89template <
typename Model, auto Member>
90consteval auto memberExists() ->
bool
95template <
typename Model,
auto Member, std::size_t... Indices>
96consteval auto memberIndexImpl(std::index_sequence<Indices...>) -> std::size_t
98 constexpr auto memberName = reflectedMemberName<Member>();
99 constexpr std::array<bool,
sizeof...(Indices)> matches{
101 for (std::size_t index = 0; index < matches.size(); ++index)
111template <
typename Model, auto Member>
112consteval auto memberIndex() -> std::size_t
115 static_assert(result < reflection::fieldCount<Model>,
116 "ORM_MODEL_MEMBER: a mapped member is not an aggregate field");
120template <
auto... Members>
121constexpr auto uniqueMemberNames() ->
bool
123 const auto nameStorage = std::tuple{reflectedMemberName<Members>()...};
125 std::apply([](
const auto&... name) {
return std::array<std::string_view,
sizeof...(Members)>{name.view()...}; },
127 for (std::size_t left = 0; left < names.size(); ++left)
129 for (std::size_t right = left + 1; right < names.size(); ++right)
131 if (names[left].
compare(names[right]) == 0)
147 template <auto Member, reflection::FixedString SqlName>
151 inline static constexpr auto member = Member;
152 inline static constexpr auto sqlName = SqlName;
158 template <auto Member, reflection::FixedString SqlName>
162 static_assert(not SqlName.view().empty(),
163 "ORM_MODEL_COLUMN_MAPPING: a mapped SQL column name must not be empty");
167 template <
typename... Definitions>
170 static_assert((
requires {
172 Definitions::sqlName;
174 "ORM_MODEL_COLUMN_MAPPING: columnNames() accepts only columnName<Member, SqlName>() definitions");
176 template <
typename Model>
177 [[nodiscard]]
static consteval auto isValidFor() ->
bool
179 if constexpr (not(std::same_as<detail::member_owner_t<Definitions::member>, Model> && ...))
183 else if constexpr (not(detail::memberExists<Model, Definitions::member>() && ...))
187 else if constexpr (not(detail::isPersistentColumnMember<Definitions::member>() && ...))
191 else if constexpr (not detail::uniqueMemberNames<Definitions::member...>())
197 return ((not Definitions::sqlName.view().empty()) && ...);
201 [[nodiscard]]
consteval auto find(std::string_view memberName)
const -> std::optional<std::string_view>
203 std::string_view result;
208 if (detail::reflectedMemberName<Definitions::member>() == memberName)
210 result = Definitions::sqlName.view();
215 return found ? std::optional<std::string_view>{result} : std::nullopt;
222 template <
typename... Definitions>
229 template <auto Member, std::
size_t Length>
233 static_assert(Length > 0,
"ORM_MODEL_STRING_LENGTH: a string length must be positive");
234 inline static constexpr auto member = Member;
235 inline static constexpr auto length = Length;
238 template <auto Member, std::
size_t Length>
245 template <
typename... Definitions>
248 static_assert((
requires {
251 } && ...),
"ORM_MODEL_STRING_LENGTH: stringLengths accepts stringLength definitions");
253 template <
typename Model>
254 [[nodiscard]]
static consteval auto isValidFor() ->
bool
256 if constexpr (not(std::same_as<detail::member_owner_t<Definitions::member>, Model> && ...))
259 return (detail::memberExists<Model, Definitions::member>() && ...) &&
260 (std::same_as<detail::static_optional_value_t<detail::member_value_t<Definitions::member>>,
263 detail::uniqueMemberNames<Definitions::member...>();
266 [[nodiscard]]
consteval auto find(std::string_view memberName)
const -> std::optional<std::size_t>
268 std::optional<std::size_t> result;
269 ((detail::reflectedMemberName<Definitions::member>() == memberName ?
270 static_cast<void>(result = Definitions::length) :
271 static_cast<void>(0)),
277 template <
typename... Definitions>
283 template <
auto... Members>
287 inline static constexpr std::size_t
size =
sizeof...(Members);
289 template <
typename Model>
290 [[nodiscard]]
static consteval auto isValidFor() ->
bool
292 if constexpr (
sizeof...(Members) == 0)
298 return (std::same_as<detail::member_owner_t<Members>, Model> && ...) &&
299 (detail::memberExists<Model, Members>() && ...) &&
300 (detail::isPersistentColumnMember<Members>() && ...) && detail::uniqueMemberNames<Members...>();
304 [[nodiscard]]
constexpr auto contains(std::string_view memberName)
const ->
bool
306 if constexpr (
sizeof...(Members) == 0)
312 const auto nameStorage = std::tuple{detail::reflectedMemberName<Members>()...};
313 return std::apply([&memberName](
const auto&... name)
314 {
return ((name.view().compare(memberName) == 0) || ...); }, nameStorage);
318 template <
typename Model>
319 [[nodiscard]]
static consteval auto indices()
321 return std::array<std::size_t,
sizeof...(Members)>{detail::memberIndex<Model, Members>()...};
329 template <
auto... Members>
336 template <
auto... Members>
340 inline static constexpr std::size_t
size =
sizeof...(Members);
342 template <
typename Model>
343 [[nodiscard]]
static consteval auto isValidFor() ->
bool
345 if constexpr (
sizeof...(Members) == 0)
351 return (std::same_as<detail::member_owner_t<Members>, Model> && ...) &&
352 (detail::memberExists<Model, Members>() && ...) &&
353 (detail::isPersistentColumnMember<Members>() && ...) && detail::uniqueMemberNames<Members...>();
357 [[nodiscard]]
constexpr auto contains(std::string_view memberName)
const ->
bool
359 if constexpr (
sizeof...(Members) == 0)
365 const auto nameStorage = std::tuple{detail::reflectedMemberName<Members>()...};
366 return std::apply([&memberName](
const auto&... name)
367 {
return ((name.view().compare(memberName) == 0) || ...); }, nameStorage);
376 template <
auto... Members>
383 template <
typename T>
443 inline static constexpr auto value =
503 template <Uu
idAdaptable T>
510 template <ValueConvertible T>
514 inline static constexpr auto value = []()
consteval
519 "ORM_MODEL_VALUE_CONVERTER: the canonical converter value has no logical column type");
528 template <
typename T>
531 using field_t = std::remove_cvref_t<T>;
532 using value_t = std::remove_cv_t<detail::static_optional_value_t<field_t>>;
537 "ORM_MODEL_UUID_ADAPTER_TYPE: UuidAdapter requires the UUID logical column type");
539 "ORM_MODEL_VALUE_CONVERTER: a UUID canonical value requires the UUID logical column type");
541 "ORM_MODEL_VALUE_CONVERTER: declare either UuidAdapter or ValueConverter for a UUID type");
546 static_assert(detail::alwaysFalse<value_t>,
547 "ORM_MODEL_LOGICAL_TYPE: unsupported model field type; specialize "
548 "orm::model::LogicalTypeTraits<T>.");
552 template <
typename T>
553 inline constexpr bool isNullable = detail::StaticOptionalTraits<std::remove_cvref_t<T>>::isOptional;
562 template <auto Member, reflection::FixedString SqlName>
569 template <
typename... Definitions>
570 consteval auto columnNames(Definitions... definitions)
575 template <
auto... Members>
582 template <auto Member, std::
size_t Length>
589 template <
typename... Definitions>
595 template <
auto... Members>
602 template <
typename T>
auto compare(const SchemaSnapshot &before, const SchemaSnapshot &after, const GenerationDecisions &decisions={}) -> SchemaDiff
consteval auto primaryKey() -> PrimaryKey< Members... >
Defines an ordered, typed primary key. An empty definition makes the model explicitly keyless.
consteval auto autoIncrement() -> AutoIncrement< Members... >
Defines typed auto-increment members. Static-model validation further restricts this to one non-null ...
consteval auto columnNames(Definitions...) -> ColumnNames< Definitions... >
Groups typed SQL column-name overrides.
consteval auto logicalType() -> ColumnType
Resolves a C++ field type to its logical database type at compile time. Users may extend the closed s...
consteval auto columnName() -> ColumnName< Member, SqlName >
Creates a typed SQL column-name override.
consteval auto stringLengths(Definitions...) -> StringLengths< Definitions... >
consteval auto stringLength() -> StringLength< Member, Length >
constexpr bool isNullable
consteval auto fields() noexcept
constexpr std::size_t fieldCount
consteval auto memberName() noexcept
consteval auto stringLength()
constexpr bool is_relation_collection_v
consteval auto logicalType() -> model::ColumnType
std::chrono::year_month_day Date
consteval auto columnName()
consteval auto columnNames(Definitions... definitions)
std::chrono::local_time< std::chrono::microseconds > LocalDateTime
consteval auto stringLengths(Definitions... definitions)
consteval auto primaryKey()
consteval auto autoIncrement()
constexpr bool is_optional_relation_collection_v
std::chrono::sys_time< std::chrono::microseconds > UtcTimestamp
constexpr auto contains(std::string_view memberName) const -> bool
static constexpr std::size_t size
static consteval auto isValidFor() -> bool
Compile-time override of one aggregate member's SQL column name.
static constexpr auto member
static constexpr auto sqlName
static consteval auto isValidFor() -> bool
consteval auto find(std::string_view memberName) const -> std::optional< std::string_view >
static constexpr auto value
static constexpr auto value
static constexpr auto value
static constexpr auto value
static constexpr auto value
static constexpr auto value
static constexpr auto value
static constexpr auto value
static constexpr auto value
static constexpr auto value
static constexpr auto value
static constexpr auto value
static constexpr auto value
static constexpr auto value
static constexpr auto value
static constexpr auto value
static constexpr auto value
static constexpr auto value
static constexpr auto value
static constexpr auto value
static constexpr auto value
static constexpr std::size_t size
static consteval auto isValidFor() -> bool
constexpr auto contains(std::string_view memberName) const -> bool
static consteval auto indices()
static constexpr auto member
static constexpr auto length
consteval auto find(std::string_view memberName) const -> std::optional< std::size_t >
static consteval auto isValidFor() -> bool