#[derive(DatabaseSchema)]
{
// Attributes available to this derive:
#[tables]
}
Expand description
Generates a DatabaseSchema implementation that dispatches generic
DBMS operations to the correct concrete table types.
Given a struct annotated with #[tables(User = "users", Post = "posts")],
this macro produces:
impl<M: MemoryProvider> DatabaseSchema<M>with match-arm dispatch forselect,insert,delete,update,validate_insert,validate_update, andreferenced_tables.- An inherent
register_tablesmethod that registers all tables in aDbmsContext.
§Example
ⓘ
#[derive(DatabaseSchema)]
#[tables(User = "users", Post = "posts")]
pub struct MySchema;
// Register tables during initialization:
MySchema::register_tables(&ctx)?;§Generics
The schema struct may declare type parameters and a where clause; they are
carried over to the generated impls. Table types in #[tables(...)] may carry
generic arguments, e.g. #[tables(Demo<T> = "demo")]. Lifetime and const
generic parameters are rejected with a compile error.
§Requirements
- Each type in the
#[tables(...)]attribute must implementTableSchema.