Yao 模型字段类型列表
在 yao 中编写模型配置文件时,列的配置类型可以使用以下的类型设置,这些类型一般会直接翻译成数据库类型。
参考:https://yaoapps.com/doc/手册/Widgets/Model#命名规范
Yao 模型定义中的可使用字段:
- name,类型 string,必填项
- label,类型 string,必填项
- type,类型 string,必填项
- title,类型 string
- description,类型 string
- comment,类型 string,会写入数据库表的注释字段
- length,类型 number
- precision,类型 number
- scale,类型 number
- nullable,类型 boolean
- option,类型 list
- default,类型 String|Integer|Float
- default_raw,类型 string 字段默认值,支持数据库函数,如 NOW() default 和 default_raw 同时存在 default_raw 优先级高
- generate,类型 string// Increment, UUID,...
- crypt,类型 string // 字段加密存储方式(MySQL Only)。许可值 AES, PASSWORD
- index,类型 boolean
- unique,类型 boolean
- primary,类型 boolean
- origin,类型 any,未使用
字符串
- string,额外属性:Length,默认长度 200
- char,额外属性:Length
长文本
- text
- mediumText
- longText
二进制
- binary,额外属性:Length
日期与时间
- date
- datetime,可选额外属性:Length
- datetimeTz,带时区的日期时间,可选额外属性:Length
- time,可选额外属性:Length
- timeTz,带时区的时间,可选额外属性:Length
- timestamp,可选额外属性:Length
- timestampTz,带时区的时间戳,可选额外属性:Length
有符号数字
- tinyInteger,微整型
- smallInteger,小整型
- integer, 整型
- bigInteger,长整型
无符号数字
- unsignedTinyInteger
- unsignedSmallInteger
- unsignedInteger
- unsignedBigInteger
自增长
- id, ID,自增长数字
- bigIncrements,自增长数字,与类型 ID 相同
- tinyIncrements,自增长
- smallIncrements,自增长
- increments,自增长
浮点
需要额外属性:Precision (field length)精度(字段长度), Scale(decimal places)范围(小数位数)
float,单精度浮点数值,4 个字节,精确到小数点后面 6 位
double,双精度浮点数值,8 个字节,精确到小数点后的 15 位
decimal,128 位高精度浮点数,常用于金融运算,不会出现浮点数计算的误差。一般用于保存金额,价格。
unsignedFloat
unsignedDouble
unsignedDecimal
decimal 型比浮点型计算精度要高,通常使用更少的空间。所以通常我们在设置小数的时候,都是用的 decimal 类型。
布尔
- Boolean, boolean
与数据库相关的类型
- json, JSON
- jsonb, JSONB
- uuid
- ipAddress
- macAddress
- enum,需要额外属性 option
- year