#[non_exhaustive]pub enum DatabaseBackend {
Sqlite(SqliteDatabase),
Postgres(PostgresDatabase),
MySql(MySqlDatabase),
Mongo(MongoDatabase),
}Expand description
One database a record is stored in — as the backend it actually is.
A VARIANT per backend rather than one struct with a kind discriminant, so a backend’s own
vocabulary is structural: MongoDatabase has a collection and no schema, and there is no
way to build a mongo backend carrying one. A shape that carried both and refused the wrong
combination at parse time could still represent it, and something downstream would eventually
have to ask.
A Vec of these on Persist rather than an Option per backend, because DECLARATION ORDER is
load-bearing: the rows emit in the order the author wrote them, so an expansion is stable and
diffable. Four Option fields would impose an arbitrary fixed order instead. The cost is that
a Vec can hold Sqlite twice where four Options could not — so “one block per database”
moves from structural to CHECKED, and the parser’s set_once on the block is now the only thing
between the model and a state it can represent. refuses_a_repeated_persist_block_or_option pins
that refusal, and a mutation proves the pin.
Three of these four payloads are near-identical today, and that is measured rather than
assumed: table/collection is one slot with two spellings, schema is the only SQL-only
option, and the FIELD-level option set (rename, type, indexed, unique, copy, the
conversions) diverges not at all. So SqliteDatabase, PostgresDatabase and MySqlDatabase
start as the same three fields.
They are separate anyway, and deliberately: the divergence that is coming is per BACKEND rather
than per family — MySQL’s engine and charset, Postgres’s index methods and tablespace, SQLite’s
journal mode, Mongo’s write concern. Splitting a shared SqlDatabase later would touch every
emission site that named it, where four small structs localise each arrival to one variant. The
duplication is four fields, which is cheap; the later split would not be. If that divergence
never arrives, this is the decision to reverse, and the measurement above is what to reverse it
against.
CLOSED, and not an oversight in a framework that otherwise refuses closed sets: codegen has to
KNOW a backend to emit its code — its derives, its rename attribute, its dialect — so a
third-party backend is a change to this crate whichever shape this takes. Openness for backends
lives where the spec puts it: traits, visitors, and a codegen plugin. #[non_exhaustive] so
adding the next variant is not a breaking change for anyone matching from outside.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Sqlite(SqliteDatabase)
SQLite.
Postgres(PostgresDatabase)
PostgreSQL.
MySql(MySqlDatabase)
MySQL.
Mongo(MongoDatabase)
MongoDB.
Implementations§
Source§impl DatabaseBackend
impl DatabaseBackend
Sourcepub const fn kind(&self) -> DatabaseKind
pub const fn kind(&self) -> DatabaseKind
Which database this is — for a message, a suffix, or a family.
Sourcepub const fn table(&self) -> Option<&RustSafeName>
pub const fn table(&self) -> Option<&RustSafeName>
The table this backend stores the record in — or the collection, which is the same option under mongo’s own word for it.
Sourcepub fn schema(&self) -> Option<&str>
pub fn schema(&self) -> Option<&str>
schema = "…", for the backends that have one. None for mongo, which has none to have.
Sourcepub fn composite_uniques(&self) -> &[CompositeUnique]
pub fn composite_uniques(&self) -> &[CompositeUnique]
unique(…) — the COMPOSITE constraints this backend holds, in written order.
EMPTY for mongo, and structurally so: the word is refused there by name, and there is no field
on MongoDatabase for one to have been stored in. schema’s own shape, for
CompositeUnique’s reason.
Sourcepub const fn comparison_name(&self) -> &Ident
pub const fn comparison_name(&self) -> &Ident
The name of the emitted COMPARISON type. _name, because comparison is the method that
EMITS it — the pair name/row reads the same way.
Sourcepub const fn columns(&self) -> &[PersistColumn]
pub const fn columns(&self) -> &[PersistColumn]
This backend’s columns, in the record’s declaration order.
Sourcepub const fn from(&self) -> &Conversion
pub const fn from(&self) -> &Conversion
The whole-row conversion that BUILDS this projection.
Sourcepub const fn into(&self) -> &Conversion
pub const fn into(&self) -> &Conversion
The whole-row conversion that LEAVES it.