#[derive(Schema)]
{
// Attributes available to this derive:
#[schema]
}
Expand description
Derives the Schema
trait.
§Attributes on structs
-
#[schema(reader_name = "name")]
: Thereader_name
attribute specifies the model reader name of database services. The names are defined in the database configuration. Default value:main
. -
#[schema(writer_name = "name")]
: Thewriter_name
attribute specifies the model writer name of database services. The names are defined in the database configuration. Default value:main
. -
#[schema(table_name = "name")]
: Thetable_name
attribute specifies the corresponding table in the database. The default table name is obtained by a concatenation of the database namespace and the model name. -
#[schema(comment = "doc")]
: Thecomment
attribute specifies the documentation of the model. The value will be used in the Avro schema.
§Attributes on struct fields
-
#[schema(ignore)]
: Theignore
annotation is used to skip a particular field such that it maps to no database column. -
#[schema(type_name = "name")]
: Thetype_name
attribute is used to override the Rust data type of the column. -
#[schema(column_name = "name")]
: All column names are assumed to be in snake-case. You can override it by specifying thecolumn_name
attribute. -
#[schema(column_type = "type")]
: The column type is derived automatically from the mappings of Rust data types for different database drivers. You can override it by specifying thecolumn_type
attribute. -
#[schema(length = N)]
: Thelength
attribute specifies the fixed string length which will override thecolumn_type
asCHAR(N)
. -
#[schema(max_length = N)]
: Themax_length
attribute specifies the maximum number of characters which will override thecolumn_type
asVARCHAR(N)
. -
#[schema(not_null)]
: Thenot_null
annotation is used to indicate that the column value can not beNULL
. -
#[schema(default_value = "value")]
: Thedefault_value
attribute specifies a default column value. If the value is a function, it must be callable asfn() -> T
. -
#[schema(auto_increment)]
: Theauto_increment
annotation is used to automatically fill in default column values. -
#[schema(auto_random)]
: Theauto_increment
annotation is used to automatically assign values to aBIGINT
column. Values assigned automatically are random and unique. The feature is only supported by TiDB. -
#[schema(index_type = "type")]
: Theindex_type
attribute is used to create an index for the database column. Supported values:btree
|hash
|gin
|spatial
|text
|unique
. -
#[schema(reference = "Model")]
: Thereference
attribute specifies the referenced model to define a relation between two models. It will be used for constriaint check and query population. -
#[schema(comment = "doc")]
: Thecomment
attribute specifies the documentation of the column. The value will be used in the OpenAPI docs. -
#[schema(primary_key)]
: Theprimary_key
annotation is used to mark a column as the primary key. -
#[schema(foreign_key)]
: Theforeign_key
annotation is used to mark a column as the foreign key. -
#[schema(read_only)]
: Theread_only
annotation is used to indicate that the column is read-only and can not be modified after creation. -
#[schema(write_only)]
: Thewrite_only
annotation is used to indicate that the column is write-only and can not be seen by frontend users. -
#[schema(exact_filter)]
: Theexact_filter
annotation is used to indicate that the column will use an exact equality filter when unspecified. -
#[schema(fuzzy_search)]
: Thefuzzy_search
annotation is used to indicate that the column supports fuzzy search. -
#[schema(on_delete = "action")]
: Theon_delete
attribute specifies the referential action for a foreign key when the parent table has aDELETE
operation. Supported values:cascade
|restrict
. -
#[schema(on_update = "action")]
: Theon_update
attribute specifies the referential action for a foreign key when the parent table has anUPDATE
operation. Supported values:cascade
|restrict
.