字段表达式
Example :
{
"fields": {
"name": "varchar(100) required",
"email": "varchar(100) format email"
}
}
JSON Schema
Field Pattern | Type | Description |
---|---|---|
{name} | string |
{name}是具体字段的名称,对应的值是一个表达式 |
表达式语法
表达式本质是Field Object用一行字符串来进行简化表示,多个属性之间通过空格分割。
下面是每个属性的表示方式:
Name / Pattern | Description |
---|---|
column {name} | 指定数据库字段名,不指定按默认规则生成,如name -> name ,firstName -> first_name |
{type} | 表示字段类型,不包括长度,详细请看字段类型 |
{type}(length) | 如varchar(100) ,表示字段类型和长度 |
{type}(precision,scale) | 如decimal(19,8) ,表示字段类型和长度 |
identity | 表示该字段为主键 |
primary key | 等同于identity |
required | 表示不能为空 |
optional | 表示允许为空 |
not null | 等同于required |
null | 表示可以为空,等同于optional |
nullable | 等同于null ,表示可以为空 |
increment | 设置字段为自增长的主键 |
auto_increment | 等同于increment |
value {value} | 设置固定值,value 是一个JSON格式的简单数值或者是一个环境变量 |
default {value} | 设置默认值,value 是一个JSON格式的简单数值或者是一个环境变量 |
columnDefault {value} | 设置物理字段的默认值 |
update false | 表示该字段只能被insert ,不能被update |
logical | 表示字段是逻辑字段,不映射到数据库物理字段 |
internal | 表示该字段不发布到接口定义中 |
sortable | 表示该字段可用于排序表达式 |
filterable | 表示该字段可用于过滤表达式 |
uuid | 等同于varchar(36) value uuid ,具体请看环境变量 |
short_uuid | 等同于varchar(36) value short_uuid ,具体请看环境变量 |
short_id | 等同于varchar(36) value short_id ,具体请看环境变量 |
map | 设置字段的数据类型为map<string,object>,同时默认设置字段类型为varchar(4000) |
map<string,{type}> | 设置字段的数据类型为map<string,{type}> |
array | 设置字段的数据类型为array<object>,同时默认设置字段类型为varchar(2000) |
array<{type}> | 设置字段的数据类型为array<{type}> |
format {name} | 设置字段的格式,如format email |
options {name} | 设置字段选项集的名称,详细请看字段选项集 |
input {name} | 设置字段的输入类型 |
meaning {name} | 设置字段的含义,目前内置支持title summary description createdAt updatedAt createdBy updatedBy 共7个含义,如果字段的name 和内置的含义一致,该字段的含义会被自动设置 |
length[min,max] | 设置字段的最小和最大长度,如length[10,] , length[10,100] ,length[,100] |
range[min,max] | 设置字段的最小和最大数字,如range[1,] ,range[1,10] ,range[,10] |
pattern[{regex}] | 设置字段的校验正则表达式 |
enum[{values}] | 设置枚举值,如enum[1,2] ,enum['created','updated'] |
- |
设置字段的描述,- 符号后的所有内容会被作为字段的描述,如varchar(100) - The description |
jmms还支持表达式和JSON Object
混合使用,通过一个特殊的$
属性:
{
"fields" : {
"firstName": {
"$" : "varchar(100) required",
"description": "The description"
}
}
}