Skip to main content

entity

Attribute Macro entity 

Source
#[entity]
Expand description

Defines a model stored in a database table. Needs table = "..." and exactly one #[key] field.

Generates typed field references (Product::code), a ProductId key type, validation and a schema.

ⓘ
#[entity(table = "products")]
pub struct Product {
    #[key]
    pub id: ProductId,
    #[rule(required, max_len = 20)]
    pub code: String,
}