Simplify item ids

This commit is contained in:
Tobie Morgan Hitchcock 2016-09-14 22:28:00 +01:00
parent 58871a420a
commit ed474b8415
4 changed files with 18 additions and 16 deletions

View file

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

View file

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

View file

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

View file

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