#[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
Unknown #[prax(...)] keys are rejected with a compile error.
§Struct-level
#[prax(table = "table_name")]- Map to a different table name#[prax(schema = "schema_name")]- NOT YET SUPPORTED: rejected with a compile error by the derive macro
§Field-level
#[prax(id)]- Mark as primary key#[prax(auto)]- Auto-increment field#[prax(unique)]- Unique constraint#[prax(default = "value")]- Database-side default value. The expression is applied by the database (e.g. via migrations), not by generated code; its presence makes the field optional in the generatedCreateInput#[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>,
}