Simplify item ids
This commit is contained in:
parent
58871a420a
commit
ed474b8415
4 changed files with 18 additions and 16 deletions
|
@ -40,6 +40,8 @@ func (this *Doc) Blaze(ast *sql.SelectStatement) (res interface{}) {
|
||||||
doc.Set(e, v.Alias)
|
doc.Set(e, v.Alias)
|
||||||
case *sql.Null:
|
case *sql.Null:
|
||||||
doc.Set(nil, v.Alias)
|
doc.Set(nil, v.Alias)
|
||||||
|
case *sql.Thing:
|
||||||
|
doc.Set(e.String(), v.Alias)
|
||||||
case *sql.Ident:
|
case *sql.Ident:
|
||||||
doc.Set(this.current.Get(e.ID).Data(), v.Alias)
|
doc.Set(this.current.Get(e.ID).Data(), v.Alias)
|
||||||
case *sql.All:
|
case *sql.All:
|
||||||
|
|
|
@ -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.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
|
return this
|
||||||
|
|
||||||
|
|
|
@ -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
|
// Set fields
|
||||||
|
err = this.setFld()
|
||||||
err = this.mrgFld()
|
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
|
return
|
||||||
|
|
||||||
|
@ -172,6 +172,8 @@ func getMrgItemRHS(doc *data.Doc, expr sql.Expr) interface{} {
|
||||||
return val
|
return val
|
||||||
case []interface{}, map[string]interface{}:
|
case []interface{}, map[string]interface{}:
|
||||||
return val
|
return val
|
||||||
|
case *sql.Thing:
|
||||||
|
return val
|
||||||
case *sql.Ident:
|
case *sql.Ident:
|
||||||
return doc.Get(val.ID).Data()
|
return doc.Get(val.ID).Data()
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,6 @@
|
||||||
package item
|
package item
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/abcum/surreal/sql"
|
"github.com/abcum/surreal/sql"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -28,7 +26,7 @@ func (this *Doc) Yield(output sql.Token, fallback sql.Token) (res interface{}) {
|
||||||
|
|
||||||
switch output {
|
switch output {
|
||||||
case sql.ID:
|
case sql.ID:
|
||||||
res = fmt.Sprintf("@%v:%v", this.key.TB, this.key.ID)
|
res = this.id
|
||||||
case sql.DIFF:
|
case sql.DIFF:
|
||||||
res = this.diff().Data()
|
res = this.diff().Data()
|
||||||
case sql.AFTER:
|
case sql.AFTER:
|
||||||
|
|
Loading…
Reference in a new issue