pub struct Persist {
pub backends: Vec<DatabaseBackend>,
pub table: Option<RustSafeName>,
}Expand description
Where a record is stored, and what each database’s row holds.
The declared DATABASES are the storage selection: persist(sqlite, postgres(…)) stores the record
in those two and nowhere else, and a record with no persist(…) block has no Persist at all.
Nothing is inferred from a field’s type or name — a column exists because a field carried the
marker.
§The NAMES and the SCHEMA are BOTH emitted now, and this is what closed the gap
A record’s table name reaches the expansion: RecordModel::table_name resolves a database’s
own table = "…" against the record’s, and emit::query’s binding writes the result into
SqlQuery::ADDRESS and into the scope aliases beside it. So do the COLUMN names and their
shapes, through SqlQuery::COLUMNS, and the whole read and write lane is rendered over them.
The BLUEPRINT — ingraph’s Describe<Db>, whose Table carries the type each column is STORED
AT, whether it holds NULL, which fields take an index, which take a UNIQUE one, and which
collections hang an edge table off the row — is emitted beside them, one per declared ∩
compiled-in SQL dialect. So PersistColumn::nullable, PersistColumn::indexed and
PersistColumn::unique reach a statement, and a record’s schema is its declaration’s rather
than a second text kept beside it. emit::query’s roster is where the emission and its one
condition are.
§The two obstacles this note recorded, and what each turned out to need
There was no type WORD to emit. A Table’s Column carries the dialect’s own spelling —
INTEGER, int8, BIGINT — and nothing derived one from a field’s Rust type. sqlx’s own
Type<Db>::type_info() was the nearest existing authority and did not serve: its words are
INT8/INT4/FLOAT8 on PostgreSQL where information_schema.data_type answers
bigint/integer/double precision, and VARCHAR with no length on MySQL, which that dialect
will not create — and the drift audit compares with eq_ignore_ascii_case and nothing else, so
an emission through those names would have failed its own audit on two dialects of three. What
closed it is a FOURTH FACE on the type rather than a table in this crate: ingraph‘s
StoredAs<Db>, open the way ColumnKind is open, whose rows are written in each catalogue’s own
reported spelling and measured against live servers. Every derive that mints a column type mints
its row with it — a vocabulary enum at its stored form’s word, a flags set at the width its
dialect holds the bits at, a newtype at its inner type’s, and a fields(record) fragment at the
CONCATENATION of its parts’.
A composite column’s name could not be spelled here. A descriptor’s columns were FLAT and a
row’s are by FIELD, so a tb: Timebase would have had to arrive as tb_num and tb_den — a
string that exists nowhere, the segments being joined at RENDER time and never in a const. What
closed it is Table::shaped, which takes the row’s own ColumnShape list and leaves every name
to the renderer, so the join stays exactly where the law already put it and this macro never has
to see that a field spans two columns.
§What the emission still cannot spell, and where each lands
Neither is a gap in this model, and both are stated at the point a reader meets them:
- a collection this database keeps in a COLUMN — a PostgreSQL array — has no word, the two
readers of one wanting two different strings. That database gets NO blueprint; it is a
documented SKIP on
emit::query’s roster, not an error, so such a record keeps every lane it had.postgres(edge)lands the schema. - a field whose TYPE has no
StoredAs<Db>row —TimeRanged<T>, whose arity depends on a type parameter — isE0277at that field, spanned there. A macro reading tokens cannot skip on a fact about a type, and the trait’s own#[diagnostic::on_unimplemented]names the<db>(type = "…")road out.
Fields§
§backends: Vec<DatabaseBackend>The declared backends, in the order they were WRITTEN — see DatabaseBackend for why the
order is kept and what keeping it costs. Never empty: a persist(…) naming no database is
refused, so a Persist that exists carries at least one row to emit.
table: Option<RustSafeName>table = "…" — the name every declared database uses unless it named its own.
Left where the declaration put it rather than resolved onto each DatabaseBackend, because
the two are answers to different questions and a DDL lane wants both: the common name is the
record’s one table name, and a per-database one is an override a reader should be able to see
as an override.
Both are EMITTED, through one resolution: Persist::table_of picks the database’s own name
over the record’s and RecordModel::table_name falls back to the record’s in snake case,
and what emit::query writes into SqlQuery::ADDRESS is that answer. So the table a query
selects from and the table a migration creates come from the same function — literally the
same const, since the blueprint PROJECTS SqlQuery::ADDRESS rather than restating it. Which
is what makes the one name safe to leave unresolved here.
Implementations§
Source§impl Persist
impl Persist
Sourcepub fn table_of<'a>(
&'a self,
database: &'a DatabaseBackend,
) -> Option<&'a RustSafeName>
pub fn table_of<'a>( &'a self, database: &'a DatabaseBackend, ) -> Option<&'a RustSafeName>
The table (or collection) one database stores the record in: its own name, or the common one.