Use actual @things not strings for item ids
This commit is contained in:
parent
d37862e385
commit
c08e9d69c9
3 changed files with 13 additions and 10 deletions
|
@ -484,6 +484,10 @@ type Thing struct {
|
|||
ID interface{}
|
||||
}
|
||||
|
||||
func (this Thing) Bytes() []byte {
|
||||
return []byte(this.String())
|
||||
}
|
||||
|
||||
func (this Thing) String() string {
|
||||
return fmt.Sprintf("@%s:%v", this.TB, this.ID)
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ import (
|
|||
type Doc struct {
|
||||
kv kvs.KV
|
||||
tx kvs.TX
|
||||
id string
|
||||
id *sql.Thing
|
||||
key *keys.Thing
|
||||
initial *data.Doc
|
||||
current *data.Doc
|
||||
|
@ -57,7 +57,7 @@ func New(kv kvs.KV, tx kvs.TX, key *keys.Thing, vars *data.Doc) (this *Doc) {
|
|||
this.current = data.New().Decode(kv.Val())
|
||||
}
|
||||
|
||||
this.id = fmt.Sprintf("%v", this.key.ID)
|
||||
this.id = sql.NewThing(this.key.TB, this.key.ID)
|
||||
|
||||
return this
|
||||
|
||||
|
@ -160,14 +160,14 @@ func (this *Doc) PurgeIndex() (err error) {
|
|||
if index.Uniq == true {
|
||||
for _, o := range old {
|
||||
key := &keys.Index{KV: this.key.KV, NS: this.key.NS, DB: this.key.DB, TB: this.key.TB, IX: index.Name, FD: o}
|
||||
this.tx.CDel(key.Encode(), []byte(this.id))
|
||||
this.tx.CDel(key.Encode(), this.id.Bytes())
|
||||
}
|
||||
}
|
||||
|
||||
if index.Uniq == false {
|
||||
for _, o := range old {
|
||||
key := &keys.Point{KV: this.key.KV, NS: this.key.NS, DB: this.key.DB, TB: this.key.TB, IX: index.Name, FD: o, ID: this.key.ID}
|
||||
this.tx.CDel(key.Encode(), []byte(this.id))
|
||||
this.tx.CDel(key.Encode(), this.id.Bytes())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -189,11 +189,11 @@ func (this *Doc) StoreIndex() (err error) {
|
|||
if index.Uniq == true {
|
||||
for _, o := range old {
|
||||
oidx := &keys.Index{KV: this.key.KV, NS: this.key.NS, DB: this.key.DB, TB: this.key.TB, IX: index.Name, FD: o}
|
||||
this.tx.CDel(oidx.Encode(), []byte(this.id))
|
||||
this.tx.CDel(oidx.Encode(), this.id.Bytes())
|
||||
}
|
||||
for _, n := range now {
|
||||
nidx := &keys.Index{KV: this.key.KV, NS: this.key.NS, DB: this.key.DB, TB: this.key.TB, IX: index.Name, FD: n}
|
||||
if err = this.tx.CPut(nidx.Encode(), []byte(this.id), nil); err != nil {
|
||||
if err = this.tx.CPut(nidx.Encode(), this.id.Bytes(), nil); err != nil {
|
||||
return fmt.Errorf("Duplicate entry for %v in index '%s' on %s", n, index.Name, this.key.TB)
|
||||
}
|
||||
}
|
||||
|
@ -202,11 +202,11 @@ func (this *Doc) StoreIndex() (err error) {
|
|||
if index.Uniq == false {
|
||||
for _, o := range old {
|
||||
oidx := &keys.Point{KV: this.key.KV, NS: this.key.NS, DB: this.key.DB, TB: this.key.TB, IX: index.Name, FD: o, ID: this.key.ID}
|
||||
this.tx.CDel(oidx.Encode(), []byte(this.id))
|
||||
this.tx.CDel(oidx.Encode(), this.id.Bytes())
|
||||
}
|
||||
for _, n := range now {
|
||||
nidx := &keys.Point{KV: this.key.KV, NS: this.key.NS, DB: this.key.DB, TB: this.key.TB, IX: index.Name, FD: n, ID: this.key.ID}
|
||||
if err = this.tx.CPut(nidx.Encode(), []byte(this.id), nil); err != nil {
|
||||
if err = this.tx.CPut(nidx.Encode(), this.id.Bytes(), nil); err != nil {
|
||||
return fmt.Errorf("Multiple items with id %s in index '%s' on %s", this.key.ID, index.Name, this.key.TB)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,8 +71,7 @@ func (this *Doc) Merge(data []sql.Expr) (err error) {
|
|||
|
||||
func (this *Doc) setFld() (err error) {
|
||||
|
||||
this.current.Set(this.key.ID, "id")
|
||||
this.current.Set(this.key.TB, "tb")
|
||||
this.current.Set(this.id, "id")
|
||||
|
||||
return
|
||||
|
||||
|
|
Loading…
Reference in a new issue