Add ‘record’ as a field type

This commit is contained in:
Tobie Morgan Hitchcock 2016-11-04 09:42:00 +00:00
parent 1733f84070
commit 45be69637e
2 changed files with 12 additions and 1 deletions

View file

@ -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 {

View file

@ -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)