|
ORM C++
|
Immutable plans are available alongside the mutable orm::Query<T>, orm::ProjectionQuery<Source, Result>, and orm::Update<T> builders. A plan preserves the expression structure in its C++ type. All four backends use that structure to prepare SQL once for the schema, plan type, and SQL dialect. Execution binds the current values and hydrates the usual model or DTO result.
param<T, I>() declares a typed argument slot. Indices start at zero and must be contiguous. Reusing an index reuses its execution argument; every occurrence must declare the same type. Calls must supply exactly one compatible argument per slot in index order. The existing rules for safe numeric widening, scalar filter values, nullable fields, model ownership, and writable paths also apply to plans. A filter on an optional field takes its scalar type; std::optional arguments are available for nullable SET values.
Temporal and UUID slots use the same types as their model fields, such as param<orm::Date, 0>(), param<orm::Uuid, 0>(), or param<UserId, 0>() for an adapted UserId field. Distinct UUID domain types are not interchangeable. Slots retain their logical type through parameter collection. LocalDateTime and UtcTimestamp slots are distinct; text and other temporal types cannot substitute for them. Backend capabilities and effective runtime bounds are checked on execution, including cached SQL. SQLite native temporal types and native UUID on SQLite or MySQL fail with UnsupportedFeature before SQL; explicitly mapped Binary16 or Text36 UUID fields use their selected representation. Temporal MIN/MAX and ordering are supported; UUID typed ordering, range operations and MIN/MAX are unavailable. See Value types for mappings and nullable results.
Clause methods return a new plan. Keep the returned value:
The objects may also carry ordinary runtime values. constexpr is useful for reusable templates with argument slots, but is not required for using a plan.
The literal alias form as<"alias">(expression) retains the alias in the plan type. The existing as("alias", expression) form supplies a runtime alias.
An UPDATE plan requires at least one SET assignment and a WHERE predicate. A DELETE plan requires a WHERE predicate. These checks happen when the plan is converted or executed. The full-model select supports collection include and the existing relation predicates; projection plans return flat DTOs.
Fixed-size std::array, C arrays, and variadic IN arguments preserve their arity. Empty fixed-size IN expressions are rejected at compile time. Vectors and initializer lists have runtime cardinality and use the runtime SQL path. The same applies to raw predicates, raw ordering, and runtime aliases. Those forms retain the typed field and model checks.
plan.toDynamic(args...) binds all slots and creates the corresponding mutable select or update builder. A delete plan returns its bound typed predicate. Use conversion when later clauses depend on a runtime branch:
Expression .dynamic() creates the existing named typed facade and is available only after all expression values are concrete. Slot-bearing expressions must first be bound through their plan. See the runnable example for a complete program.