From ed474b8415e57888a0612c400a371127da906334 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Wed, 14 Sep 2016 22:28:00 +0100 Subject: [PATCH] Simplify item ids --- util/item/blaze.go | 2 ++ util/item/item.go | 2 +- util/item/merge.go | 26 ++++++++++++++------------ util/item/yield.go | 4 +--- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/util/item/blaze.go b/util/item/blaze.go index 3c8b66aa..3a1c8d98 100644 --- a/util/item/blaze.go +++ b/util/item/blaze.go @@ -40,6 +40,8 @@ func (this *Doc) Blaze(ast *sql.SelectStatement) (res interface{}) { doc.Set(e, v.Alias) case *sql.Null: doc.Set(nil, v.Alias) + case *sql.Thing: + doc.Set(e.String(), v.Alias) case *sql.Ident: doc.Set(this.current.Get(e.ID).Data(), v.Alias) case *sql.All: diff --git a/util/item/item.go b/util/item/item.go index ac38a43b..249e6c56 100644 --- a/util/item/item.go +++ b/util/item/item.go @@ -56,7 +56,7 @@ func New(kv kvs.KV, txn kvs.TX, key *keys.Thing) (this *Doc) { this.current = data.New().Decode(kv.Val()) } - this.id = fmt.Sprintf("@%v:%v", this.key.TB, this.key.ID) + this.id = fmt.Sprintf("%v", this.key.ID) return this diff --git a/util/item/merge.go b/util/item/merge.go index e462ff4f..7bf165ab 100644 --- a/util/item/merge.go +++ b/util/item/merge.go @@ -44,20 +44,20 @@ func (this *Doc) Merge(data []sql.Expr) (err error) { } } - // Set data - this.current.Set(this.id, "id") - this.current.Set(this.id, "data", "id") - - // Set time - this.current.New(time.Now(), "time", "created") - this.current.Set(time.Now(), "time", "updated") - - // Set meta - this.current.Set(this.key.TB, "meta", "table") - this.current.Set(this.key.ID, "meta", "ident") - // Set fields + err = this.setFld() err = this.mrgFld() + err = this.setFld() + + return + +} + +func (this *Doc) setFld() (err error) { + + // Set data + this.current.Set(this.key.ID, "id") + this.current.Set(this.key.TB, "tb") return @@ -172,6 +172,8 @@ func getMrgItemRHS(doc *data.Doc, expr sql.Expr) interface{} { return val case []interface{}, map[string]interface{}: return val + case *sql.Thing: + return val case *sql.Ident: return doc.Get(val.ID).Data() } diff --git a/util/item/yield.go b/util/item/yield.go index 5d4ee1d4..77e504de 100644 --- a/util/item/yield.go +++ b/util/item/yield.go @@ -15,8 +15,6 @@ package item import ( - "fmt" - "github.com/abcum/surreal/sql" ) @@ -28,7 +26,7 @@ func (this *Doc) Yield(output sql.Token, fallback sql.Token) (res interface{}) { switch output { case sql.ID: - res = fmt.Sprintf("@%v:%v", this.key.TB, this.key.ID) + res = this.id case sql.DIFF: res = this.diff().Data() case sql.AFTER: