pub trait DatabaseSchema<M, A = AccessControlList>where
M: MemoryProvider,
A: AccessControl,{
Show 16 methods
// Required methods
fn select(
&self,
dbms: &WasmDbmsDatabase<'_, M, A>,
table_name: &str,
query: Query,
) -> DbmsResult<Vec<Vec<(ColumnDef, Value)>>>;
fn aggregate(
&self,
dbms: &WasmDbmsDatabase<'_, M, A>,
table_name: &str,
query: Query,
aggregates: &[AggregateFunction],
) -> DbmsResult<Vec<AggregatedRow>>;
fn referenced_tables(
&self,
table: &'static str,
) -> Vec<(&'static str, Vec<&'static str>)>;
fn insert(
&self,
dbms: &WasmDbmsDatabase<'_, M, A>,
table_name: &'static str,
record_values: &[(ColumnDef, Value)],
) -> DbmsResult<()>;
fn delete(
&self,
dbms: &WasmDbmsDatabase<'_, M, A>,
table_name: &'static str,
delete_behavior: DeleteBehavior,
filter: Option<Filter>,
) -> DbmsResult<u64>;
fn update(
&self,
dbms: &WasmDbmsDatabase<'_, M, A>,
table_name: &'static str,
patch_values: &[(ColumnDef, Value)],
filter: Option<Filter>,
) -> DbmsResult<u64>;
fn validate_insert(
&self,
dbms: &WasmDbmsDatabase<'_, M, A>,
table_name: &'static str,
record_values: &[(ColumnDef, Value)],
) -> DbmsResult<()>;
fn validate_update(
&self,
dbms: &WasmDbmsDatabase<'_, M, A>,
table_name: &'static str,
record_values: &[(ColumnDef, Value)],
old_pk: Value,
) -> DbmsResult<()>;
fn migrate_default(table: &str, column: &str) -> Option<Value>
where Self: Sized;
fn migrate_default_dyn(&self, table: &str, column: &str) -> Option<Value>;
fn migrate_transform(
table: &str,
column: &str,
old: Value,
) -> DbmsResult<Option<Value>>
where Self: Sized;
fn migrate_transform_dyn(
&self,
table: &str,
column: &str,
old: Value,
) -> DbmsResult<Option<Value>>;
fn compiled_snapshots() -> Vec<TableSchemaSnapshot>
where Self: Sized;
fn compiled_snapshots_dyn(&self) -> Vec<TableSchemaSnapshot>;
fn renamed_from_dyn(&self, table: &str, column: &str) -> Vec<&'static str>;
// Provided method
fn select_join(
&self,
dbms: &WasmDbmsDatabase<'_, M, A>,
from_table: &str,
query: Query,
) -> DbmsResult<Vec<Vec<(JoinColumnDef, Value)>>> { ... }
}Expand description
Provides schema-driven dynamic dispatch for database operations.
Implementations of this trait know which concrete table types exist
and forward generic operations (identified by table name) to the
appropriate typed methods on WasmDbmsDatabase.
This trait is typically implemented by generated code from the
#[derive(DatabaseSchema)] macro.
Required Methods§
Sourcefn select(
&self,
dbms: &WasmDbmsDatabase<'_, M, A>,
table_name: &str,
query: Query,
) -> DbmsResult<Vec<Vec<(ColumnDef, Value)>>>
fn select( &self, dbms: &WasmDbmsDatabase<'_, M, A>, table_name: &str, query: Query, ) -> DbmsResult<Vec<Vec<(ColumnDef, Value)>>>
Performs a generic select for the given table name and query.
Sourcefn aggregate(
&self,
dbms: &WasmDbmsDatabase<'_, M, A>,
table_name: &str,
query: Query,
aggregates: &[AggregateFunction],
) -> DbmsResult<Vec<AggregatedRow>>
fn aggregate( &self, dbms: &WasmDbmsDatabase<'_, M, A>, table_name: &str, query: Query, aggregates: &[AggregateFunction], ) -> DbmsResult<Vec<AggregatedRow>>
Performs an aggregate query for the given table name
Sourcefn referenced_tables(
&self,
table: &'static str,
) -> Vec<(&'static str, Vec<&'static str>)>
fn referenced_tables( &self, table: &'static str, ) -> Vec<(&'static str, Vec<&'static str>)>
Returns tables and columns that reference the given table via foreign keys.
Sourcefn insert(
&self,
dbms: &WasmDbmsDatabase<'_, M, A>,
table_name: &'static str,
record_values: &[(ColumnDef, Value)],
) -> DbmsResult<()>
fn insert( &self, dbms: &WasmDbmsDatabase<'_, M, A>, table_name: &'static str, record_values: &[(ColumnDef, Value)], ) -> DbmsResult<()>
Performs an insert for the given table name.
Sourcefn delete(
&self,
dbms: &WasmDbmsDatabase<'_, M, A>,
table_name: &'static str,
delete_behavior: DeleteBehavior,
filter: Option<Filter>,
) -> DbmsResult<u64>
fn delete( &self, dbms: &WasmDbmsDatabase<'_, M, A>, table_name: &'static str, delete_behavior: DeleteBehavior, filter: Option<Filter>, ) -> DbmsResult<u64>
Performs a delete for the given table name.
Sourcefn update(
&self,
dbms: &WasmDbmsDatabase<'_, M, A>,
table_name: &'static str,
patch_values: &[(ColumnDef, Value)],
filter: Option<Filter>,
) -> DbmsResult<u64>
fn update( &self, dbms: &WasmDbmsDatabase<'_, M, A>, table_name: &'static str, patch_values: &[(ColumnDef, Value)], filter: Option<Filter>, ) -> DbmsResult<u64>
Performs an update for the given table name.
Sourcefn validate_insert(
&self,
dbms: &WasmDbmsDatabase<'_, M, A>,
table_name: &'static str,
record_values: &[(ColumnDef, Value)],
) -> DbmsResult<()>
fn validate_insert( &self, dbms: &WasmDbmsDatabase<'_, M, A>, table_name: &'static str, record_values: &[(ColumnDef, Value)], ) -> DbmsResult<()>
Validates an insert operation.
Sourcefn validate_update(
&self,
dbms: &WasmDbmsDatabase<'_, M, A>,
table_name: &'static str,
record_values: &[(ColumnDef, Value)],
old_pk: Value,
) -> DbmsResult<()>
fn validate_update( &self, dbms: &WasmDbmsDatabase<'_, M, A>, table_name: &'static str, record_values: &[(ColumnDef, Value)], old_pk: Value, ) -> DbmsResult<()>
Validates an update operation.
Sourcefn migrate_default(table: &str, column: &str) -> Option<Value>where
Self: Sized,
fn migrate_default(table: &str, column: &str) -> Option<Value>where
Self: Sized,
Returns the default value of a column for a given table, if any.
Looks up the table’s per-row Migrate::default_value hook, then falls back
to the #[default] attribute compiled into ColumnDef::default.
Used by the migration planner to satisfy AddColumn ops on
non-nullable columns.
Sourcefn migrate_default_dyn(&self, table: &str, column: &str) -> Option<Value>
fn migrate_default_dyn(&self, table: &str, column: &str) -> Option<Value>
Object-safe sibling of Self::migrate_default.
The macro emits a one-line dispatch to the Sized variant so callers
holding a &dyn DatabaseSchema can resolve AddColumn defaults
without re-genericising on S.
Sourcefn migrate_transform(
table: &str,
column: &str,
old: Value,
) -> DbmsResult<Option<Value>>where
Self: Sized,
fn migrate_transform(
table: &str,
column: &str,
old: Value,
) -> DbmsResult<Option<Value>>where
Self: Sized,
Transforms a stored value when migrating a column to an incompatible
type by dispatching to the table’s
Migrate::transform_column
hook.
Sourcefn migrate_transform_dyn(
&self,
table: &str,
column: &str,
old: Value,
) -> DbmsResult<Option<Value>>
fn migrate_transform_dyn( &self, table: &str, column: &str, old: Value, ) -> DbmsResult<Option<Value>>
Object-safe sibling of Self::migrate_transform.
Sourcefn compiled_snapshots() -> Vec<TableSchemaSnapshot>where
Self: Sized,
fn compiled_snapshots() -> Vec<TableSchemaSnapshot>where
Self: Sized,
Returns the compile-time TableSchemaSnapshot for every table in the
schema.
Used by drift detection (boot path) and by the migration planner to diff against the snapshots stored on disk.
Sourcefn compiled_snapshots_dyn(&self) -> Vec<TableSchemaSnapshot>
fn compiled_snapshots_dyn(&self) -> Vec<TableSchemaSnapshot>
Object-safe sibling of Self::compiled_snapshots.
WasmDbmsDatabase holds a Box<dyn DatabaseSchema>, so it cannot call
compiled_snapshots() directly (that method requires Self: Sized).
Sourcefn renamed_from_dyn(&self, table: &str, column: &str) -> Vec<&'static str>
fn renamed_from_dyn(&self, table: &str, column: &str) -> Vec<&'static str>
Returns the compile-time renamed_from chain for column on table.
Used by the migration diff stage to detect rename operations: when a compiled column does not match any stored column by name, the diff walks this list looking for a stored column under a previous name.
Provided Methods§
Sourcefn select_join(
&self,
dbms: &WasmDbmsDatabase<'_, M, A>,
from_table: &str,
query: Query,
) -> DbmsResult<Vec<Vec<(JoinColumnDef, Value)>>>
fn select_join( &self, dbms: &WasmDbmsDatabase<'_, M, A>, from_table: &str, query: Query, ) -> DbmsResult<Vec<Vec<(JoinColumnDef, Value)>>>
Performs a join query, returning results with column definitions that include source table names.