| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 | 
							- package ii
 
- import (
 
- 	"regexp"
 
- 	"golib/features/mo"
 
- )
 
- type FieldInfo struct {
 
- 	Name     string  `xml:"Name,attr"`     // 数据库字段名称
 
- 	Type     mo.Type `xml:"Type,attr"`     // 数据类型
 
- 	Required bool    `xml:"Required,attr"` // 是否必填, 默认 false
 
- 	Unique   bool    `xml:"Unique,attr"`   // 是否值唯一, 默认值为 false. 设置后此字段会变为唯一值, 并且会设置为索引
 
- 	// Items 用于 mo.TypeArray, 值为 array 或 object
 
- 	// 当值为 array 时数组需要符合 json 数组规范.
 
- 	// 值为 object 时则表示数组内的每个元素类型必须为 map[string]interface 类型
 
- 	Items string `xml:"Items,attr"`
 
- 	// Minimum 和 Maximum 用于 mo.TypeInt mo.TypeInt64 mo.TypeDouble mo.TypeDate mo.TypeDecimal128
 
- 	// 以及 mo.TypeString / mo.TypeArray / mo.TypeObject
 
- 	// 数字类型直接用于比较大小
 
- 	// mo.TypeString 用于限制字符串最大长度和最小长度
 
- 	// mo.TypeArray 用于限制数字最小长度和最大长度
 
- 	// mo.TypeObject 用于限制最大字段数量和最小字段数量
 
- 	Minimum float64 `xml:"Minimum,attr"` // 最小值
 
- 	Maximum float64 `xml:"Maximum,attr"` // 最大值
 
- 	// Enums 枚举数据, 当 len(Enums) > 0 时, 此 Field 的值或 Value 必须在其中
 
- 	Enums []string `xml:"Enums>Enum"`
 
- 	enums []any
 
- 	RequiredKey []string `xml:"RequiredKey>Key"`
 
- 	Label       string   `xml:"Label"` // 中文名称
 
- 	Value string `xml:"Value"` // 默认值, 用于读写时该字段不存在时使用。当默认值不存在时根据 Type 初始化默认值, 例如 int64 类型默认值为 0
 
- 	value any
 
- 	// Pattern 用于 mo.TypeString, 该值为一个正则表达式, 当 Pattern 不为空时会校验此字段的值是否包含在 Pattern 内
 
- 	Pattern string `xml:"Pattern"`
 
- 	pattern *regexp.Regexp
 
- 	// 关联查询
 
- 	Lookup Lookup `xml:"Lookup"`
 
- }
 
- // Lookup 用作 LocalField(FieldInfo.Name) 去 From 关联 ForeignField 的值
 
- // 例如使用用户 Id 关联用户名
 
- type Lookup struct {
 
- 	Form string `xml:"From,attr"` // 数据库表, e.g. ums.user
 
- 	// LocalField   string `xml:"LocalField,attr"`   // 本地字段, 使用 FieldInfo.Name
 
- 	ForeignField string `xml:"ForeignField,attr"` // From 表字段
 
- 	AS           string `xml:"As,attr"`           // 新的字段。 当字段不存在时, 使用 FieldInfo.Name
 
- }
 
 
  |