#[derive(Model)]
{
// Attributes available to this derive:
#[prax]
}
Expand description
Derive macro for defining Prax models manually.
This derive macro allows you to define models in Rust code instead of
using a .prax schema file. It generates the same query builder methods
and type-safe operations.
§Attributes
§Struct-level
#[prax(table = "table_name")]- Map to a different table name#[prax(schema = "schema_name")]- Specify database schema
§Field-level
#[prax(id)]- Mark as primary key#[prax(auto)]- Auto-increment field#[prax(unique)]- Unique constraint#[prax(default = value)]- Default value#[prax(column = "col_name")]- Map to different column#[prax(relation(...))]- Define relation
§Example
ⓘ
#[derive(prax::Model)]
#[prax(table = "users")]
struct User {
#[prax(id, auto)]
id: i32,
#[prax(unique)]
email: String,
#[prax(column = "display_name")]
name: Option<String>,
#[prax(default = "now()")]
created_at: chrono::DateTime<chrono::Utc>,
}