pub struct PersistColumn {
pub source: Ident,
pub name: RustSafeName,
pub domain: Type,
pub stored: Option<Type>,
pub edge: bool,
pub copy: bool,
pub nullable: bool,
pub indexed: bool,
pub unique: bool,
pub flatten: bool,
pub from: Conversion,
pub into: Conversion,
}Expand description
One column of ONE database’s row.
Per database rather than shared, because nearly everything about a column can differ between
backends: the same field may be a BeU64 on one and a Vec<u8> on another, be called
bit_rate in one table and bit_rate_v2 in the next, and be indexed in one alone.
Fields§
§source: IdentThe RECORD field this column projects — what a conversion reads and writes.
name: RustSafeNameThe column’s name in THIS database: the field’s own, the common rename, or this database’s.
domain: TypeThe record field’s declared type, verbatim.
stored: Option<Type>type = "…" — the type this database STORES, when it is not the domain one.
edge: booledge in this database’s block: this COLLECTION is kept in a second table here rather than in
a column of the row.
§It is Postgres’s word and nobody else’s, and the asymmetry is the whole design
Postgres is the one dialect with two usable strategies — a native ARRAY column for the
elements an array can hold, and the same edge table the other two dialects have no choice but
to use — and which one an element takes is a fact about the ELEMENT rather than about the
dialect. That fact lives in a trait row (ingraph’s PgCollectionStorage), and a macro
holding tokens cannot read one, so the DECLARATION is where it is stated.
§OPTIONAL, and the ground is which way each default is WRONG
Absent, the column rides the row as an array, which is the default because its failure is
LOUD: an element no array can hold has no Carrier<Postgres> row for the collection type, and
the storability audit is E0277 at the #[ingraph::record(…)] — naming the type, at the
declaration, with this word as the answer. Defaulting the other way has no such signal: every
array-eligible collection would quietly take a second table, a whole extra statement per page,
and nothing would ever say so.
So a word is asked for exactly where the compiler has already stopped, and never where it would not have. Neither direction is a claim this crate trusts: the word’s emission binds the edge kinds and the wordless path binds the array’s carrier, so both are checked at a concrete dialect.
SQLite and MySQL carry false always — ingraph-derive refuses the word there, those dialects
having no strategy to choose — so a reader of this field never has to ask which database it is
about before knowing what false means. See DatabaseKind::edge_collections, which is the
dialect’s own half of the same question.
copy: boolcopy in this database’s block: the STORED type is Copy.
Declared per database rather than taken from the domain field’s own marker, because the two
are different claims about different types and a macro has no type information to bridge
them. It shapes the row’s accessors exactly as Projection::Copied shapes the record’s.
nullable: boolWhether the column is NULLABLE.
It follows the optional MARKER, never the field’s spelled type — the macro cannot inspect
types, which is why the whole projection is marker-driven — and it is not overridable. A
domain/column disagreement fails loudly in BOTH directions (a null decoded into a required
field is a decode error; a None written to a NOT NULL column is a constraint violation),
so an override would buy better wording at the price of a knob that hides the schema bug it
reconciles.
It reaches the CREATE TABLE this record’s expansion emits — one flag per FIELD in the
blueprint’s own list — and it says the WHOLE field may be absent, which is the only thing a
marker on a field can say. There is no spelling here for this segment holds NULL and that
one does not, and there does not need to be: a leaf that holds NULL whatever its field says
declares so on its own segment, as ingraph’s ColumnShape::Nullable, and reaches the
renderer through the TYPE rather than through this flag. The renderer composes the two, so a
required MediaTimestamp still declares its derived column nullable and this marker is not
asked about it.
It also reaches the row, as it always did: a nullable column’s field is an Option, its bind
writes one NULL per column the value would occupy, and its cursor slot unwraps one.
indexed: boolindexed in this database’s block.
SPENT: ingraph’s Table::with_indexes takes the list, Table::create renders one
CREATE INDEX per field, and the emitted blueprint is what hands the list over.
A COLLECTION this database keeps in a SECOND TABLE is refused the word at the front end — there
is no column of this row to index, and the elements’ own table already carries the containment
index a list(…) wants. On a dialect that keeps the collection in a COLUMN the word stays
legal and is inert, that database having no blueprint at all; see Persist.
unique: boolunique in this database’s block: the column’s values are each held by at most one row, this
database’s own constraint to enforce.
SPENT with indexed and through the same list, and refused on a COLLECTION
wherever it is written — a row here holds MANY values and there is no single one for the
comparison to be about.
Legal beside indexed on the same field — the two words state independent intents, a seek and
a constraint, and it is the SCHEMA lane that later collapses them to one statement rather than
this model refusing the pair.
flatten: boolflatten in THIS database’s block: the field’s own name is dropped, so its type’s columns join
the holder’s namespace — num/den where the same field unmarked gives tb_num/tb_den.
§It is a NAMING knob, and flattening is the default beneath it
A field whose type spans several columns is flattened wherever it is stored; what this decides is only whether the field’s name PREFIXES those columns. So the word adds no layout and removes one segment, and a collision with a column the holder already has falls to the same-name refusal by name rather than being prefixed away silently.
§PER DATABASE, because it is one database’s schema decision
It was common while it was read as a layout claim. It is not one: a legacy table whose columns
are already num/den is a fact about that database, and the axis law puts a per-database
decision in the database’s block. Mongo’s block has no flatten at all — its default IS the
nested subdocument, so there is no prefix there to drop — which makes the invalid state
unspellable rather than refused, and mongo(flatten) still refuses by name.
The macro cannot check the type — tb: Timebase and title: String are the same tokens — so
what refuses flatten on a single-column field is the SEGMENT COUNT, at
ingraph’s flattened: an E0080 where the row’s COLUMNS is evaluated.
from: Conversionfrom BUILDS the row, so domain → stored: what a WRITE applies to this column.
into: Conversioninto LEAVES the row, so stored → domain: what a READ applies to this column.
Implementations§
Source§impl PersistColumn
impl PersistColumn
Sourcepub const fn ty(&self) -> &Type
pub const fn ty(&self) -> &Type
The type the emitted row’s field carries: the type override, or the domain type.
Sourcepub fn declared(&self) -> String
pub fn declared(&self) -> String
What the DECLARATION calls this column — the record’s own field name, unraw’d.
The CONSTANT axis of the declared→stored pairing: name is per database and
this is the same string in every one of them, which is what makes it the key a reverse
relation’s field = "…" is looked up by. It is the field’s name and not its rename, because
a rename — common or per database — is a STORAGE word, and the vocabulary a neighbouring
declaration writes is the record’s own.
Unraw’d, so a field spelled r#type is declared type: a field = "…" literal is a name
somebody writes rather than Rust tokens, and the raw prefix is a fact about the token.