Skip to main content

DatabaseSchema

Derive Macro DatabaseSchema 

Source
#[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 for select, insert, delete, update, validate_insert, validate_update, and referenced_tables.
  • An inherent register_tables method that registers all tables in a [DbmsContext].

§Example

#[derive(DatabaseSchema)]
#[tables(User = "users", Post = "posts")]
pub struct MySchema;

// Register tables during initialization:
MySchema::register_tables(&ctx)?;

§Requirements

  • Each type in the #[tables(...)] attribute must implement [TableSchema].
  • The generated types (UserInsertRequest, UserUpdateRequest, UserRecord, etc.) must be in scope.