23export import :database_numeric;
29template <
typename T,
typename SchemaType, std::
size_t FieldIndex>
30[[nodiscard]]
consteval auto mappedColumnPointer() noexcept -> const model::ColumnView*
33 for (
const auto& column : descriptor->columns)
35 if (column.fieldIndex == FieldIndex)
43template <
typename T,
typename SchemaType, std::
size_t FieldIndex>
44inline constexpr auto mappedColumn = mappedColumnPointer<T, SchemaType, FieldIndex>();
46template <
typename T,
typename SchemaType, std::
size_t FieldIndex>
47[[nodiscard]]
constexpr auto columnForField() noexcept -> const model::ColumnView&
49 static_assert(mappedColumn<T, SchemaType, FieldIndex> !=
nullptr,
50 "A bound field must have a column descriptor in the selected schema");
51 return *mappedColumn<T, SchemaType, FieldIndex>;
54template <
typename T,
typename SchemaType>
55[[nodiscard]]
constexpr auto columnForField(std::size_t fieldIndex) ->
const model::ColumnView&
58 for (
const auto& column : descriptor->columns)
60 if (column.fieldIndex == fieldIndex)
65 throw std::invalid_argument{
"A bound field has no column descriptor in the selected schema"};
69template <
typename T,
typename SchemaType,
bool JoinedValues = false>
72 static_assert(SchemaType::template contains<std::remove_cv_t<T>>,
"BindingPayload model must belong to its Schema");
82 template <std::
size_t FieldIndex>
85 return detail::columnForField<std::remove_cv_t<T>, SchemaType, FieldIndex>();
90 return detail::columnForField<std::remove_cv_t<T>, SchemaType>(fieldIndex);
100 return std::lexicographical_compare(left.begin(), left.end(), right.begin(), right.end(),
101 [](
const auto& lhs,
const auto& rhs) { return (lhs <=> rhs) < 0; });
126 using value_t = std::remove_cv_t<T>;
132 throw std::invalid_argument{
"Primary-key field must not be NULL: " + fieldName};
143 catch (
const std::invalid_argument&)
145 throw ConversionError{
"A primary-key value was rejected by its converter"};
158 throw std::invalid_argument{
"Unsupported primary-key field type: " + fieldName};
162template <
typename SchemaType,
typename T>
165 static_assert(SchemaType::template contains<std::remove_cv_t<T>>,
166 "A primary key can be read only from a model in the selected Schema");
170 key.reserve(descriptor->primaryKeyIndices.size());
172 auto appendPrimaryKeyField = [&key]<
typename Index>(Index,
const auto* field)
174 using field_t = std::decay_t<
decltype(*field)>;
182 constexpr auto* column = detail::mappedColumn<std::remove_cv_t<T>, SchemaType, Index::value>;
183 if constexpr (column !=
nullptr)
185 if (column->isPrimaryKey)
197 throw std::invalid_argument{
"Relation endpoint must define a non-empty primary key"};
205 if (values.get_indicator(name) == soci::i_null)
207 throw ConversionError{
"Cannot hydrate NULL relation primary key: " + name};
216 catch (
const std::invalid_argument&)
218 throw ConversionError{
"Cannot hydrate relation primary key without data loss: " + name};
240 return fromStorage(values.template get<std::string>(name));
253 throw std::invalid_argument{
"Unsupported relation primary-key column: " + name};
258 std::vector<const model::ColumnView*> columns;
259 columns.reserve(
model->primaryKeyIndices.size());
261 for (
const auto columnIndex :
model->primaryKeyIndices)
263 if (columnIndex >=
model->columns.size())
265 throw std::invalid_argument{
"Primary-key descriptor points outside the model columns"};
268 const auto& column =
model->columns[columnIndex];
271 throw std::invalid_argument{
"Relations with model-valued primary-key fields are not supported"};
273 columns.push_back(&column);
278 throw std::invalid_argument{
"Relation endpoint must define a non-empty primary key"};
286 return std::format(
"__orm_owner_{}", column.name);
Internal signal for a result value that cannot be represented by the requested model or projection fi...
A value that can be bound as a query parameter.
std::variant< int, long long, unsigned long long, double, std::string, Date, TimeOfDay, LocalDateTime, UtcTimestamp, Uuid > Value
static auto fromStorage(model::ColumnType logicalType, Value value) -> QueryValue
Restores a canonical transport value with its model-level type.
auto getPrimaryKeyColumns(const model::ModelView &model) -> std::vector< const model::ColumnView * >
auto getEncodedScalarValue(const auto &values, const std::string &name) -> T
auto encodeScalarValue(const T &value) -> std::string
auto getPrimaryKey(const T &object) -> PrimaryKey
auto getNumericValue(const auto &values, const std::string &fieldName) -> Result
std::vector< query::QueryValue > PrimaryKey
auto canonicalUuid(const T &value) -> Uuid
auto relationOwnerAlias(const model::ColumnView &column) -> std::string
auto getPrimaryKeyValue(const auto &values, const std::string &name, model::ColumnType type) -> query::QueryValue
constexpr bool isOptional
auto toPrimaryKeyValue(const T &value, const std::string &fieldName) -> query::QueryValue
auto toQueryValue(const query::QueryValue &value) -> query::QueryValue
constexpr bool isNullable
constexpr auto modelView() noexcept -> ModelView
constexpr auto fieldPointers(T &value) noexcept
constexpr auto constexpr_for_tuple(Tuple &&t, F &&f, Args... args) -> void
constexpr bool is_relation_collection_v
static constexpr auto modelDescriptor() noexcept -> model::ModelView
static constexpr bool joinedValues
static constexpr auto columnDescriptor() noexcept -> const model::ColumnView &
static constexpr auto columnDescriptor(std::size_t fieldIndex) -> const model::ColumnView &
auto operator()(const PrimaryKey &left, const PrimaryKey &right) const -> bool
Trivially-copyable handle to one model in immutable Schema storage.