zino_derive

Derive Macro Model

Source
#[derive(Model)]
{
    // Attributes available to this derive:
    #[schema]
}
Expand description

Derives the Model trait.

§Attributes on structs

  • #[schema(model_name = "name")]: The default model name is obtained by converting the struct name to snake-case. You can override it by specifying the model_name attribute.

  • #[schema(item_name = "name")]: The item_name attribute specifies the corresponding field for a single model data item. Default value: entry.

  • #[schema(item_name_plural = "name")]: The item_name_plural attribute specifies the corresponding field for model data items. Default value: entries.

§Attributes on struct fields

  • #[schema(ignore)]: The ignore annotation is used to skip a particular field such that it disables the derived setter.

  • #[schema(constructor = "path")]: The constructor attribute is used to create a new instance of the column type in Model::new(). The function must be callable as fn() -> T.

  • #[schema(composable)]: The composable annotation indicates that the column value relates to a particular model. It is only valid for the data type M, Option<M> or Vec<M>, where M is a model.

  • #[schema(read_only)]: The read_only annotation indicates that the column is read-only and can not be modified after creation. It also can not been seen in the model definition.

  • #[schema(generated)]: The generated annotation indicates that the column value is generated by the backend and do not need any frontend input. The column will not been seen in the model definition.

  • #[schema(reserved)]: The generated annotation is used to mark a special column. It will not been seen in the model definition. Built-in reserved fields: created_at | updated_at | deleted_at | is_deleted | is_locked | is_archived | version | edition.

  • #[schema(auto_initialized)]: The auto_initialized annotation indicates that the column has an automatically initialized value. Different to the generated column, an auto_initialized value can be modified after creation. The column will not been seen in the model definition.

  • #[schema(inherent)]: The inherent annotation indicates that the column value is parsed by an associated function in the model’s inherent implementation.