pub trait TableSchema: Encode + 'static {
type Record: TableRecord<Schema = Self>;
type Insert: InsertRecord<Schema = Self>;
type Update: UpdateRecord<Schema = Self>;
type ForeignFetcher: ForeignFetcher;
// Required methods
fn table_name() -> &'static str;
fn columns() -> &'static [ColumnDef];
fn primary_key() -> &'static str;
fn to_values(self) -> Vec<(ColumnDef, Value)>;
fn sanitizer(column_name: &'static str) -> Option<Box<dyn Sanitize>>;
fn validator(column_name: &'static str) -> Option<Box<dyn Validate>>;
// Provided methods
fn indexes() -> &'static [IndexDef] { ... }
fn foreign_fetcher() -> Self::ForeignFetcher { ... }
fn schema_snapshot() -> TableSchemaSnapshot { ... }
fn fingerprint() -> u64 { ... }
}Expand description
Table schema representation.
It is used to define the structure of a database table.
Required Associated Types§
Sourcetype Record: TableRecord<Schema = Self>
type Record: TableRecord<Schema = Self>
The TableRecord type associated with this table schema;
which is the data returned by a query.
Sourcetype Insert: InsertRecord<Schema = Self>
type Insert: InsertRecord<Schema = Self>
The InsertRecord type associated with this table schema.
Sourcetype Update: UpdateRecord<Schema = Self>
type Update: UpdateRecord<Schema = Self>
The UpdateRecord type associated with this table schema.
Sourcetype ForeignFetcher: ForeignFetcher
type ForeignFetcher: ForeignFetcher
The ForeignFetcher type associated with this table schema.
Required Methods§
Sourcefn table_name() -> &'static str
fn table_name() -> &'static str
Returns the name of the table.
Sourcefn primary_key() -> &'static str
fn primary_key() -> &'static str
Returns the name of the primary key column.
Sourcefn to_values(self) -> Vec<(ColumnDef, Value)>
fn to_values(self) -> Vec<(ColumnDef, Value)>
Converts itself into a vector of column-value pairs.
Provided Methods§
Sourcefn indexes() -> &'static [IndexDef]
fn indexes() -> &'static [IndexDef]
Returns the list of indexes defined on the table, where each index is represented by the list of column names it includes.
Sourcefn foreign_fetcher() -> Self::ForeignFetcher
fn foreign_fetcher() -> Self::ForeignFetcher
Returns an instance of the ForeignFetcher for this table schema.
Sourcefn schema_snapshot() -> TableSchemaSnapshot
fn schema_snapshot() -> TableSchemaSnapshot
Builds a self-describing TableSchemaSnapshot from the compile-time schema definition.
The snapshot captures the structural shape of the table — name, primary key, alignment, columns and indexes — in a stable, encodable form so it can be persisted to stable memory and later diffed against the snapshot of a previous version to derive the migration steps required to bring the on-disk layout up to date.
The default implementation assembles the snapshot from Self::table_name,
Self::primary_key, Self::columns, Self::indexes and the Encode::ALIGNMENT
constant. It is sufficient for every schema generated by #[derive(Table)]; implementors
that carry metadata not exposed through ColumnDef (e.g. column defaults or non-default
foreign-key ON DELETE actions) should override it.
Sourcefn fingerprint() -> u64
fn fingerprint() -> u64
Returns the fingerprint of the table schema.
The fingerprint is computed as a hash of Self::table_name so that the same table keeps
the same identity across rebuilds (where std::any::TypeId is not stable) and across
schema evolution. Two distinct types declaring the same table_name are intentionally
considered the same logical table.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".