#[derive(Model)]
{
// Attributes available to this derive:
#[table]
#[column]
#[primary_key]
}
Available on crate feature
macros and (crate features model-mysql or model-postgres or model-sqlite) only.Expand description
Derive rust_web_server::model::Model for a struct.
§Struct attributes
| Attribute | Meaning |
|---|---|
#[table(name = "tbl")] | Override table name (default: struct name lowercased) |
§Field attributes
| Attribute | Meaning |
|---|---|
#[primary_key] | Mark as primary key |
#[primary_key(auto_increment)] | Auto-increment primary key |
#[column(name = "col")] | Override column name |
#[column(unique)] | Mark column unique (informational) |
#[ignore] | Exclude from DB mapping |
§Example
ⓘ
#[derive(rust_web_server::Model, Debug, Clone)]
#[table(name = "users")]
pub struct User {
#[primary_key(auto_increment)]
pub id: i64,
#[column(name = "first_name")]
pub name: String,
pub email: String,
#[ignore]
pub display_label: String,
}