#[derive(Table)]
{
// Attributes available to this derive:
#[table]
#[column]
}
Expand description
Derives the Table trait for a struct, generating type-safe column accessors.
§Attributes
#[table(name = "table_name")]- Specifies the SQL table name (optional, defaults to snake_case of struct name)
§Field Attributes
#[column(primary_key)]- Marks the field as primary key#[column(name = "column_name")]- Specifies the SQL column name (optional, defaults to field name)#[column(nullable)]- Marks the column as nullable#[column(unique)]- Marks the column as UNIQUE#[column(autoincrement)]- Marks the column as AUTOINCREMENT#[column(default = "expr")]- Sets a raw SQL default expression
§Generated Items
For a struct User, this macro generates:
UserTable- A type implementingTabletrait with table metadataUserColumns- A module containing column types (Id,Name, etc.)- Column accessor methods on
UserTable