30inline constexpr unsigned char typeToken{};
39 return TypeId{&detail::typeToken<T>};
56 inline constexpr auto noTargetModel = std::numeric_limits<std::size_t>::max();
62 std::string_view
name;
68 std::optional<ColumnType>
type;
98 [[nodiscard]]
constexpr auto isConfigured() const noexcept ->
bool
129 [[nodiscard]]
constexpr auto findColumn(std::string_view fieldOrSqlName)
const noexcept ->
const ColumnView*
131 for (std::size_t columnIndex = 0; columnIndex <
columns.size(); ++columnIndex)
133 const auto& column =
columns[columnIndex];
134 if (column.fieldName.compare(fieldOrSqlName) == 0 || column.name.compare(fieldOrSqlName) == 0)
144 for (std::size_t relationIndex = 0; relationIndex <
relations.size(); ++relationIndex)
146 const auto& relation =
relations[relationIndex];
147 if (relation.fieldName.compare(fieldOrSqlName) == 0)
152 for (std::size_t relationIndex = 0; relationIndex <
relations.size(); ++relationIndex)
154 const auto& relation =
relations[relationIndex];
155 if (relation.columnName.compare(fieldOrSqlName) == 0)
165 for (std::size_t relationIndex = 0; relationIndex <
relations.size(); ++relationIndex)
167 const auto& relation =
relations[relationIndex];
168 if (relation.fieldName.compare(fieldName) == 0)
187 [[nodiscard]]
constexpr auto valid()
const noexcept -> bool;
188 [[nodiscard]]
constexpr explicit operator bool() const noexcept;
189 [[nodiscard]] constexpr auto operator==(std::nullptr_t) const noexcept ->
bool;
190 [[nodiscard]] constexpr auto operator==(const
ModelView&) const noexcept ->
bool = default;
191 [[nodiscard]] constexpr auto operator*() const noexcept -> const
ModelView&;
192 [[nodiscard]] constexpr auto operator->() const noexcept -> const
ModelDataView*;
195 [[nodiscard]] constexpr auto
findColumn(std::string_view fieldOrSqlName) const noexcept -> const
ColumnView*;
196 [[nodiscard]] constexpr auto
198 [[nodiscard]] constexpr auto
203 [[nodiscard]] constexpr auto
primaryKeySize() const noexcept -> std::
size_t;
211 std::span<const ModelDataView* const>
models;
213 [[nodiscard]]
constexpr auto at(std::size_t index)
const noexcept ->
ModelView
218 [[nodiscard]]
constexpr auto find(
TypeId type)
const noexcept ->
ModelView
220 for (std::size_t index = 0; index < models.size(); ++index)
222 if (models[index]->type == type)
230 [[nodiscard]]
constexpr auto findTable(std::string_view
tableName)
const noexcept ->
ModelView
232 for (std::size_t index = 0; index < models.size(); ++index)
250constexpr ModelView::operator bool() const noexcept
277 return valid() ? data().findColumn(fieldOrSqlName) :
nullptr;
282 return valid() ? data().findRelation(fieldOrSqlName) :
nullptr;
287 return valid() ? data().findRelationField(fieldName) :
nullptr;
296 return schema->at(column.targetModelIndex);
301 if (not valid() || relation.targetModelIndex ==
noTargetModel)
305 return schema->at(relation.targetModelIndex);
310 if (relation.junction.isConfigured())
312 return relation.junction;
319 const auto target = resolveTarget(relation);
320 const auto* owningRelation = target ? target.findRelationField(relation.mappedBy) :
nullptr;
322 not owningRelation->junction.isConfigured())
328 .tableName = owningRelation->junction.tableName,
329 .ownerColumns = owningRelation->junction.targetColumns,
330 .targetColumns = owningRelation->junction.ownerColumns,
337 return valid() ?
data().primaryKeyIndices.size() : 0U;
340static_assert(std::is_trivially_copyable_v<ModelView>);
341static_assert(
sizeof(ModelView) ==
sizeof(
const SchemaView*) +
sizeof(std::size_t));
342static_assert(std::is_trivially_copyable_v<SchemaView>);
constexpr auto noTargetModel
consteval auto tableName() -> std::string_view
consteval auto typeId() noexcept -> TypeId
consteval auto relations(Descriptors... descriptors)
consteval auto uuidStorage() -> model::UuidStorageDefinition< Member, Backend, Storage >
std::optional< std::size_t > maxStringLength
UuidStorage sqliteUuidStorage
constexpr auto operator==(const ColumnView &) const noexcept -> bool=default
std::optional< ColumnType > type
std::size_t targetModelIndex
UuidStorage mysqlUuidStorage
std::string_view fieldName
constexpr auto isConfigured() const noexcept -> bool
std::string_view tableName
std::span< const std::string_view > ownerColumns
std::span< const std::string_view > targetColumns
Immutable data stored once for a model inside a closed schema.
constexpr auto findRelation(std::string_view fieldOrSqlName) const noexcept -> const RelationView *
constexpr auto findColumn(std::string_view fieldOrSqlName) const noexcept -> const ColumnView *
std::string_view tableName
std::string_view typeName
std::span< const RelationView > relations
constexpr auto findRelationField(std::string_view fieldName) const noexcept -> const RelationView *
std::span< const std::size_t > primaryKeyIndices
std::span< const ColumnView > columns
Trivially-copyable handle to one model in immutable Schema storage.
constexpr auto findRelationField(std::string_view fieldName) const noexcept -> const RelationView *
constexpr auto resolveJunction(const RelationView &relation) const noexcept -> JunctionView
constexpr auto primaryKeySize() const noexcept -> std::size_t
constexpr auto valid() const noexcept -> bool
constexpr auto operator->() const noexcept -> const ModelDataView *
constexpr auto findColumn(std::string_view fieldOrSqlName) const noexcept -> const ColumnView *
constexpr auto data() const noexcept -> const ModelDataView &
const SchemaView * schema
constexpr auto resolveTarget(const ColumnView &column) const noexcept -> ModelView
constexpr auto findRelation(std::string_view fieldOrSqlName) const noexcept -> const RelationView *
constexpr auto operator*() const noexcept -> const ModelView &
constexpr auto operator==(std::nullptr_t) const noexcept -> bool
std::string_view mappedBy
std::string_view columnName
std::size_t targetModelIndex
std::string_view fieldName
Immutable view over a statically materialized schema.
constexpr auto at(std::size_t index) const noexcept -> ModelView
std::span< const ModelDataView *const > models
constexpr auto operator==(const TypeId &) const noexcept -> bool=default