DB Schema
https://uniapp.dcloud.net.cn/uniCloud/schema.html#db-schema概述
上传schema
- 在单个schema文件右键可以只上传当前的schema
- 在database目录右键可以上传全部schema
下载schema
- database目录右键可以下载所有schema及扩展校验函数
*.schema.json
- 在单个schema文件右键可以只上传当前选中的schema。快捷键是【Ctrl+u】。(Ctrl+u是HBuilderX的通用快捷键,不管是发布App还是上传云函数、schema,都是Ctrl+u)
设置数据库操作权限
设置database/*.schema.json
bsonType
字段类型required
必填项permission
字段控制权限,对应查增改删
properties
字段表示表字段
示例
json
{
"bsonType": "object",
"required": [
"name"
],
"permission": {
"read": true,
"create": true,
"update": true,
"delete": true
},
"properties": {
"_id": {
"description": "ID,系统自动生成",
"order": 0
},
"name": {
"bsonType": "string",
"label": "文章标题",
"errorMessage": {
"required": "{label}不能为空",
"format": "{label}格式无效"
},
"order": 1,
"description": "文章的标题说明",
"trim": "both"
},
"content": {
"bsonType": "string",
"label": "内容",
"order": 2,
"description": "文字内容",
"trim": "both"
},
"postType": {
"bsonType": "timestamp",
"label": "发布时间",
"errorMessage": {
"format": "{label}格式无效"
},
"forceDefaultValue": {
"$env": "now"
},
"order": 3,
"description": "发布时间"
},
"hits": {
"bsonType": "int",
"label": "阅读量",
"errorMessage": {
"format": "{label}格式无效"
},
"order": 4,
"description": "阅读量",
"exclusiveMinimum": true,
"exclusiveMaximum": true,
"defaultValue": "33"
}
}
}
{
"bsonType": "object",
"required": [
"name"
],
"permission": {
"read": true,
"create": true,
"update": true,
"delete": true
},
"properties": {
"_id": {
"description": "ID,系统自动生成",
"order": 0
},
"name": {
"bsonType": "string",
"label": "文章标题",
"errorMessage": {
"required": "{label}不能为空",
"format": "{label}格式无效"
},
"order": 1,
"description": "文章的标题说明",
"trim": "both"
},
"content": {
"bsonType": "string",
"label": "内容",
"order": 2,
"description": "文字内容",
"trim": "both"
},
"postType": {
"bsonType": "timestamp",
"label": "发布时间",
"errorMessage": {
"format": "{label}格式无效"
},
"forceDefaultValue": {
"$env": "now"
},
"order": 3,
"description": "发布时间"
},
"hits": {
"bsonType": "int",
"label": "阅读量",
"errorMessage": {
"format": "{label}格式无效"
},
"order": 4,
"description": "阅读量",
"exclusiveMinimum": true,
"exclusiveMaximum": true,
"defaultValue": "33"
}
}
}
foreignKey
https://uniapp.dcloud.net.cn/uniCloud/schema.html#foreignkey字段外键
通过foreignKey外键字段,建立不同表之间的关联关系
它的前半部分是另一张表的表名,中间用.
分割,后半部分是另一张表的字段名
js
"userid": {
"bsonType": "string",
"label": "用户id",
"errorMessage": {
"required": "{label}不能为空",
"format": "{label}格式无效"
},
"foreignKey": "uni-id-users._id",
"forceDefaultValue": {
"$env": "uid"
},
"order": 2,
"trim": "both"
}
"userid": {
"bsonType": "string",
"label": "用户id",
"errorMessage": {
"required": "{label}不能为空",
"format": "{label}格式无效"
},
"foreignKey": "uni-id-users._id",
"forceDefaultValue": {
"$env": "uid"
},
"order": 2,
"trim": "both"
}