Skip to main content

DatabaseSchema

Trait DatabaseSchema 

Source
pub trait DatabaseSchema<M, A = AccessControlList>{
    // Required methods
    fn select(
        &self,
        dbms: &WasmDbmsDatabase<'_, M, A>,
        table_name: &str,
        query: Query,
    ) -> DbmsResult<Vec<Vec<(ColumnDef, Value)>>>;
    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<()>;

    // Provided method
    fn select_join(
        &self,
        dbms: &WasmDbmsDatabase<'_, M, A>,
        from_table: &str,
        query: Query,
    ) -> DbmsResult<Vec<Vec<(CandidColumnDef, 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§

Source

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.

Source

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.

Source

fn insert( &self, dbms: &WasmDbmsDatabase<'_, M, A>, table_name: &'static str, record_values: &[(ColumnDef, Value)], ) -> DbmsResult<()>

Performs an insert for the given table name.

Source

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.

Source

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.

Source

fn validate_insert( &self, dbms: &WasmDbmsDatabase<'_, M, A>, table_name: &'static str, record_values: &[(ColumnDef, Value)], ) -> DbmsResult<()>

Validates an insert operation.

Source

fn validate_update( &self, dbms: &WasmDbmsDatabase<'_, M, A>, table_name: &'static str, record_values: &[(ColumnDef, Value)], old_pk: Value, ) -> DbmsResult<()>

Validates an update operation.

Provided Methods§

Source

fn select_join( &self, dbms: &WasmDbmsDatabase<'_, M, A>, from_table: &str, query: Query, ) -> DbmsResult<Vec<Vec<(CandidColumnDef, Value)>>>

Performs a join query, returning results with column definitions that include source table names.

Implementors§