From 45be69637e48caabc71e83e6db8c23e34d914d6c Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Fri, 4 Nov 2016 09:42:00 +0000 Subject: [PATCH] =?UTF-8?q?Add=20=E2=80=98record=E2=80=99=20as=20a=20field?= =?UTF-8?q?=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/type.go | 2 +- util/item/each.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/sql/type.go b/sql/type.go index 2b071003..7b84a7e1 100644 --- a/sql/type.go +++ b/sql/type.go @@ -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 { diff --git a/util/item/each.go b/util/item/each.go index 4850bdf5..52908a43 100644 --- a/util/item/each.go +++ b/util/item/each.go @@ -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)