nodedb_sql/planner/defaults/mod.rs
1// SPDX-License-Identifier: Apache-2.0
2
3//! Column DEFAULT expression compilation and evaluation at insert time.
4//!
5//! A declared DEFAULT is stored in the catalog as text. [`ColumnDefaults`]
6//! compiles that text ONCE per statement; the per-row path evaluates the
7//! compiled form and never sees a string, so it cannot re-parse.
8//!
9//! Supported forms: ID generation functions (UUIDv4/v7, ULID, CUID2, NANOID),
10//! `NOW()`, sequence accessors (`nextval`, `currval`), literals, and any other
11//! expression the plan-time const-folder can resolve.
12//!
13//! A DEFAULT that cannot be evaluated raises [`crate::SqlError::UnevaluableDefault`].
14//! The column is never omitted: an omitted column stores NULL where the
15//! declaration promised a value, and nothing reports it.
16//!
17//! Lives in the planner because every engine's rows materialize their
18//! DEFAULTs there, before declared-type coercion and range checks run, so a
19//! materialized default is validated exactly like a supplied one and a
20//! `DEFAULT now()` means the same thing on every engine.
21
22mod compiled;
23mod convert;
24mod kind;
25
26pub use compiled::{ColumnDefaults, CompiledDefault, validate_default_expr};
27pub use convert::default_value_to_sql;