Implicit primary key
#[derive(Model)] requires a primary key. The attribute macro #[rango::model] adds one when missing, then derives Model.
Behavior
- If no primary key is declared, it injects
pub id: FieldUuidas the first field. #[rango::model(pk = "bigint")]injectsid: FieldAutoBigInt, assigned by the database on insert.#[rango::model(pk = "int")]injectsid: FieldAutoInt."uuid"is the default.- If a primary key already exists (
idfield or#[field(primary_key)]), nothing is injected. #[derive(Model)]is added unless already present, so the struct can still carry#[model(...)]and#[field(...)]attributes.
Use #[rango::model] as written. It is not imported in the prelude, on purpose, to avoid clashing with other model names.
The default is set per model, not in rango.toml. Cargo does not track that file, so builds would go stale when it changes.
Example
#[rango::model]
struct Article {
title: FieldVarchar<1, 200>,
body: FieldText,
}
// Article now has `pub id: FieldUuid`.
#[rango::model(pk = "bigint")]
struct Event {
name: FieldVarchar<1, 100>,
}
// Event has `id: FieldAutoBigInt`, assigned by the database on insert.