#[derive(ModelAccessor)]
{
// Attributes available to this derive:
#[schema]
}
Expand description
Derives the ModelAccessor
trait.
§Attributes on structs
-
#[schema(auto_rename)]
: Theauto_rename
annotation is used to rename the field name automatically when fetching data of the referenced model. -
#[schema(unique_on = "field_1, field_2, ...")]
: Theunique_on
attribute specifies the composite columns on which the model is considered to be unique.
§Attributes on struct fields
-
#[schema(aliase = "name")]
: Thealiase
attribute specifies the field name inModelAccessor
to be accessed. -
#[schema(primary_key)]
: Theprimary_key
annotation is used to mark a column as the primary key. -
#[schema(snapshot)]
: Thesnapshot
annotation is used to indicate that the column should be included in a query population. Built-in snapshot fields:id
|name
|status
|updated_at
|version
. -
#[schema(reference = "Model")]
: Thereference
attribute specifies the referenced model to define a relation between two models. It will be used for constraint check and query population. -
#[schema(fetch_as = "field")]
: Thefetch_as
attribute specifies the field name when fetching data of the referenced model. -
#[schema(translate_as = "field")]
: Thetranslate_as
attribute specifies the field name when translating the model data. -
#[schema(unique)]
: Theunique
annotation is used to indicate that the column value should be unique in the table. -
#[schema(not_null)]
: Thenot_null
annotation is used to indicate that the column has a not-null constraint. It also prohibits the cases when theString
value is empty or theUuid
value isnil
. -
#[schema(nonempty)]
: Thenonempty
annotation is used to indicate that theString
,Vec<T>
orMap
value should be nonempty. -
#[schema(validator = "validator")]
: Thevalidator
attribute specifies a custom validator which is used to validate the string value. If the value is a function, it must be callable asfn() -> T
. -
#[schema(format = "format")]
: Theformat
attribute specifies the format of aString
value. Supported values:alphabetic
|alphanumeric
|ascii
|ascii-alphabetic
|ascii-alphanumeric
|ascii-digit
|ascii-hexdigit
|ascii-lowercase
|ascii-uppercase
|credit-card
|date
|date-time
|email
|host
|hostname
|ip
|ipv4
|ipv6
|lowercase
|numeric
|phone-number
|regex
|time
|uppercase
|uri
|uuid
. -
#[schema(locale = "lang")]
: Thelocale
attribute specifies the language for the column value. It will be used in data mocking. Supported values:en
|es
|de
|fr
|zh
. -
#[schema(enum_values = "value1 | value2 | ...")]
: Theenum_values
attribute specifies the enumerated values for aString
orVec<String>
value. -
#[schema(length = N)]
: Thelength
attribute specifies the fixed length for aString
value. -
#[schema(max_length = N)]
: Themax_length
attribute specifies the maximum number of characters for aString
value. -
#[schema(min_length = N)]
: Themax_length
attribute specifies the minimum number of characters for aString
value. -
#[schema(max_items = N)]
: Themax_items
attribute specifies the maximum number of items for aVec<T>
value. -
#[schema(min_items = N)]
: Themax_items
attribute specifies the minimum number of items for aVec<T>
value. -
#[schema(scale = N)]
: Thescale
attribute specifies the scale for aDecimal
value. -
#[schema(unique_items)]
: Theunique_items
annotation is used to indicate that the array items should be unique. -
#[schema(minimum = integer)]
: Theminimum
attribute specifies the minimum integer for the column value. -
#[schema(maximum = integer)]
: Themaximum
attribute specifies the maximum integer for the column value. -
#[schema(less_than = "value")]
: Theless_than
attribute specifies a comparison relation in which the column value is less than another column. If the value is a function, it must be callable asfn() -> T
. -
#[schema(greater_than = "value")]
: Theless_than
attribute specifies a comparison relation in which the column value is greater than another column. If the value is a function, it must be callable asfn() -> T
.