Add ‘record’ as a field type
This commit is contained in:
parent
1733f84070
commit
45be69637e
2 changed files with 12 additions and 1 deletions
|
@ -16,7 +16,7 @@ package sql
|
|||
|
||||
func (p *parser) parseType() (exp string, err error) {
|
||||
|
||||
allowed := []string{"any", "url", "uuid", "color", "email", "phone", "array", "object", "domain", "string", "number", "double", "custom", "boolean", "datetime", "latitude", "longitude"}
|
||||
allowed := []string{"any", "url", "uuid", "color", "email", "phone", "array", "object", "domain", "record", "string", "number", "double", "custom", "boolean", "datetime", "latitude", "longitude"}
|
||||
|
||||
_, lit, err := p.shouldBe(IDENT, CUSTOM)
|
||||
if err != nil {
|
||||
|
|
|
@ -247,6 +247,17 @@ func (this *Doc) chck(fld *sql.DefineFieldStatement, key string, old, val interf
|
|||
}
|
||||
}
|
||||
|
||||
case "record":
|
||||
if cnv, ok := val.(*sql.Thing); ok {
|
||||
this.current.Set(cnv, key)
|
||||
} else {
|
||||
if fld.Validate {
|
||||
return fmt.Errorf("Field '%v' needs to be a record, but found '%v'", key, val)
|
||||
} else {
|
||||
this.current.Iff(old, key)
|
||||
}
|
||||
}
|
||||
|
||||
case "string":
|
||||
if cnv, err := conv.ConvertToString(val); err == nil {
|
||||
this.current.Set(cnv, key)
|
||||
|
|
Loading…
Reference in a new issue