Derive Macro atmosphere::Schema
source · #[derive(Schema)]
{
// Attributes available to this derive:
#[sql]
}
Expand description
A derive macro that processes structs to automatically generate schema-related code. It reads custom attributes and derives necessary traits and implementations for interacting with the database.
Attributes:
#[sql(pk)]- Mark a column as primary key#[sql(fk -> OtherModel)]- Mark a column as foreign key onOtherModel#[sql(unique)]- Mark a column as unique#[sql(timestamp = [create|update|delete])]- Mark a column as timestamp#[sql(.., rename = "renamed_sql_col")]- Rename a column in the generated sql
Usage:
#[derive(Schema)]
struct User {
#[sql(pk)]
id: i32,
#[sql(unique)]
username: String,
#[sql(timestamp = create)]
created_at: chrono::DateTime<chrono::Utc>
}
#[derive(Schema)]
struct Post {
#[sql(pk)]
id: i32,
#[sql(fk -> User, rename = "author_id")]
author: i32,
}