定义实体
本文档详细介绍如何在 manifest.yaml 文件中定义实体。
配置
要使用自定义实体存储,需要在 manifest.yaml 文件中使用 storage 属性进行定义,其语法格式如下:
yaml
storage:
entities:
- name: employees
attributes:
- name: name
type: string
required: true
default: ''
- name: description
type: string
- name: age
type: number
indexes:
- name: 'name_age_'
keys:
- name: 1
- age: 1
options:
unique: true详细的定义请参考 Storage 。
属性
自定义实体的属性限制规则
| 分类 | 要求 |
|---|---|
name | 实体名称必须遵循: - 满足正则表达式: ^[a-z0-9][a-z0-9_-]*(?:\.[a-z0-9_-]+)*$ - 名称不能重复 - 名称长度不能少于 3 个字符,不超过 64 个字符 |
attributes | 属性名称必须遵循: - 满足正则表达式: ^[a-zA-Z][_a-zA-Z0-9-.]*$ - 单个实体内属性名称唯一 - 最长 64 个字符 |
indexes | 索引名称必须遵循: - 满足正则表达式: ^[a-zA-Z][a-zA-Z0-9_]*$ - 同一实体中的每个索引名称都必须唯一 - 名称长度不能短于 3 个字符,不超过 64 个字符 |
数据类型
自定义实体是带有多个类型化或非类型化属性的 key。你可以使用以下数据类型定义属性:
| 类型 | 要求 |
|---|---|
number | Int ,Float,Double |
string | UTF-8 字符串 |
boolean | true 或 false |
object | Json 数据类型 |
array | 数组类型支持如下数据类型: - number - string - boolean - object |
注意事项
- 已经部署在开发/生产环境的实体不能被删除
- 实体中已经声明的属性不能再次删除或者修改类型
- 实体中已经声明的
required不能由选填改为必填