Skip to main content

DatabaseBackend

Enum DatabaseBackend 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Sqlite(SqliteDatabase)

SQLite.

§

Postgres(PostgresDatabase)

PostgreSQL.

§

MySql(MySqlDatabase)

MySQL.

§

Mongo(MongoDatabase)

MongoDB.

Implementations§

Source§

impl DatabaseBackend

Source

pub const fn kind(&self) -> DatabaseKind

Which database this is — for a message, a suffix, or a family.

Source

pub const fn storage(&self) -> &Storage

What every backend carries.

Source

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.

Source

pub fn schema(&self) -> Option<&str>

schema = "…", for the backends that have one. None for mongo, which has none to have.

Source

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.

Source

pub const fn name(&self) -> &Ident

The name of the emitted ROW type.

Source

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.

Source

pub const fn columns(&self) -> &[PersistColumn]

This backend’s columns, in the record’s declaration order.

Source

pub const fn from(&self) -> &Conversion

The whole-row conversion that BUILDS this projection.

Source

pub const fn into(&self) -> &Conversion

The whole-row conversion that LEAVES it.

Trait Implementations§

Source§

impl Clone for DatabaseBackend

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DatabaseBackend

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.