Don’t use of ClrL, GetL, DelL, PutL methods on KV store

Remove the need to query a particular KV level, and instead use slightly different encoded keys, and use prefix based iteration. This means we can use different KV stores to give the same functionality, without needing to use hierarchical KV stores.
This commit is contained in:
Tobie Morgan Hitchcock 2018-02-09 15:08:27 +00:00
parent 8cce4ad185
commit 84b72e25d2
28 changed files with 327 additions and 256 deletions

View file

@ -26,7 +26,10 @@ func (e *executor) executeRemoveNamespace(ctx context.Context, ast *sql.RemoveNa
e.dbo.DelNS(ast.Name.ID) e.dbo.DelNS(ast.Name.ID)
nkey := &keys.NS{KV: ast.KV, NS: ast.Name.ID} nkey := &keys.NS{KV: ast.KV, NS: ast.Name.ID}
_, err = e.dbo.ClrP(nkey.Encode(), 0) _, err = e.dbo.Clr(nkey.Encode())
akey := &keys.Namespace{KV: ast.KV, NS: ast.Name.ID}
_, err = e.dbo.ClrP(akey.Encode(), 0)
return return
@ -37,7 +40,10 @@ func (e *executor) executeRemoveDatabase(ctx context.Context, ast *sql.RemoveDat
e.dbo.DelDB(ast.NS, ast.Name.ID) e.dbo.DelDB(ast.NS, ast.Name.ID)
dkey := &keys.DB{KV: ast.KV, NS: ast.NS, DB: ast.Name.ID} dkey := &keys.DB{KV: ast.KV, NS: ast.NS, DB: ast.Name.ID}
_, err = e.dbo.ClrP(dkey.Encode(), 0) _, err = e.dbo.Clr(dkey.Encode())
akey := &keys.Database{KV: ast.KV, NS: ast.NS, DB: ast.Name.ID}
_, err = e.dbo.ClrP(akey.Encode(), 0)
return return
@ -94,7 +100,13 @@ func (e *executor) executeRemoveTable(ctx context.Context, ast *sql.RemoveTableS
} }
tkey := &keys.TB{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB.TB} tkey := &keys.TB{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB.TB}
_, err = e.dbo.ClrP(tkey.Encode(), 0) _, err = e.dbo.Clr(tkey.Encode())
if err != nil {
return nil, err
}
akey := &keys.Table{KV: ast.KV, NS: ast.NS, DB: ast.DB, TB: TB.TB}
_, err = e.dbo.ClrP(akey.Encode(), 0)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -23,7 +23,7 @@ type TX struct {
pntr *rixxdb.TX pntr *rixxdb.TX
} }
func one(all kvs.KV, err error) (kvs.KV, error) { func one(res *rixxdb.KV, err error) (kvs.KV, error) {
switch err { switch err {
case nil: case nil:
@ -34,11 +34,11 @@ func one(all kvs.KV, err error) (kvs.KV, error) {
return nil, &kvs.KVError{} return nil, &kvs.KVError{}
} }
return all, err return res, err
} }
func many(all []kvs.KV, err error) ([]kvs.KV, error) { func many(res []*rixxdb.KV, err error) ([]kvs.KV, error) {
switch err { switch err {
case nil: case nil:
@ -49,7 +49,13 @@ func many(all []kvs.KV, err error) ([]kvs.KV, error) {
return nil, &kvs.KVError{} return nil, &kvs.KVError{}
} }
return all, err var out = make([]kvs.KV, len(res))
for i, v := range res {
out[i] = v
}
return out, err
} }
@ -66,138 +72,61 @@ func (tx *TX) Commit() error {
} }
func (tx *TX) Clr(key []byte) (kvs.KV, error) { func (tx *TX) Clr(key []byte) (kvs.KV, error) {
all, err := tx.pntr.Clr(key) res, err := tx.pntr.Clr(key)
return one(all, err) return one(res, err)
}
func (tx *TX) ClrL(key []byte, max uint64) ([]kvs.KV, error) {
all, err := tx.pntr.ClrL(key, max)
out := make([]kvs.KV, len(all))
for i, v := range all {
out[i] = v
}
return many(out, err)
} }
func (tx *TX) ClrP(key []byte, max uint64) ([]kvs.KV, error) { func (tx *TX) ClrP(key []byte, max uint64) ([]kvs.KV, error) {
all, err := tx.pntr.ClrP(key, max) res, err := tx.pntr.ClrP(key, max)
out := make([]kvs.KV, len(all)) return many(res, err)
for i, v := range all {
out[i] = v
}
return many(out, err)
} }
func (tx *TX) ClrR(beg []byte, end []byte, max uint64) ([]kvs.KV, error) { func (tx *TX) ClrR(beg []byte, end []byte, max uint64) ([]kvs.KV, error) {
all, err := tx.pntr.ClrR(beg, end, max) res, err := tx.pntr.ClrR(beg, end, max)
out := make([]kvs.KV, len(all)) return many(res, err)
for i, v := range all {
out[i] = v
}
return many(out, err)
} }
func (tx *TX) Get(ver int64, key []byte) (kvs.KV, error) { func (tx *TX) Get(ver int64, key []byte) (kvs.KV, error) {
all, err := tx.pntr.Get(uint64(ver), key) res, err := tx.pntr.Get(uint64(ver), key)
return one(all, err) return one(res, err)
}
func (tx *TX) GetL(ver int64, key []byte, max uint64) ([]kvs.KV, error) {
all, err := tx.pntr.GetL(uint64(ver), key, max)
out := make([]kvs.KV, len(all))
for i, v := range all {
out[i] = v
}
return many(out, err)
} }
func (tx *TX) GetP(ver int64, key []byte, max uint64) ([]kvs.KV, error) { func (tx *TX) GetP(ver int64, key []byte, max uint64) ([]kvs.KV, error) {
all, err := tx.pntr.GetP(uint64(ver), key, max) res, err := tx.pntr.GetP(uint64(ver), key, max)
out := make([]kvs.KV, len(all)) return many(res, err)
for i, v := range all {
out[i] = v
}
return many(out, err)
} }
func (tx *TX) GetR(ver int64, beg []byte, end []byte, max uint64) ([]kvs.KV, error) { func (tx *TX) GetR(ver int64, beg []byte, end []byte, max uint64) ([]kvs.KV, error) {
all, err := tx.pntr.GetR(uint64(ver), beg, end, max) res, err := tx.pntr.GetR(uint64(ver), beg, end, max)
out := make([]kvs.KV, len(all)) return many(res, err)
for i, v := range all {
out[i] = v
}
return many(out, err)
} }
func (tx *TX) Del(ver int64, key []byte) (kvs.KV, error) { func (tx *TX) Del(ver int64, key []byte) (kvs.KV, error) {
all, err := tx.pntr.Del(uint64(ver), key) res, err := tx.pntr.Del(uint64(ver), key)
return one(all, err) return one(res, err)
} }
func (tx *TX) DelC(ver int64, key []byte, exp []byte) (kvs.KV, error) { func (tx *TX) DelC(ver int64, key []byte, exp []byte) (kvs.KV, error) {
return tx.pntr.DelC(uint64(ver), key, exp) res, err := tx.pntr.DelC(uint64(ver), key, exp)
} return one(res, err)
func (tx *TX) DelL(ver int64, key []byte, max uint64) ([]kvs.KV, error) {
all, err := tx.pntr.DelL(uint64(ver), key, max)
out := make([]kvs.KV, len(all))
for i, v := range all {
out[i] = v
}
return many(out, err)
} }
func (tx *TX) DelP(ver int64, key []byte, max uint64) ([]kvs.KV, error) { func (tx *TX) DelP(ver int64, key []byte, max uint64) ([]kvs.KV, error) {
all, err := tx.pntr.DelP(uint64(ver), key, max) res, err := tx.pntr.DelP(uint64(ver), key, max)
out := make([]kvs.KV, len(all)) return many(res, err)
for i, v := range all {
out[i] = v
}
return many(out, err)
} }
func (tx *TX) DelR(ver int64, beg []byte, end []byte, max uint64) ([]kvs.KV, error) { func (tx *TX) DelR(ver int64, beg []byte, end []byte, max uint64) ([]kvs.KV, error) {
all, err := tx.pntr.DelR(uint64(ver), beg, end, max) res, err := tx.pntr.DelR(uint64(ver), beg, end, max)
out := make([]kvs.KV, len(all)) return many(res, err)
for i, v := range all {
out[i] = v
}
return many(out, err)
} }
func (tx *TX) Put(ver int64, key []byte, val []byte) (kvs.KV, error) { func (tx *TX) Put(ver int64, key []byte, val []byte) (kvs.KV, error) {
all, err := tx.pntr.Put(uint64(ver), key, val) res, err := tx.pntr.Put(uint64(ver), key, val)
return one(all, err) return one(res, err)
} }
func (tx *TX) PutC(ver int64, key []byte, val []byte, exp []byte) (kvs.KV, error) { func (tx *TX) PutC(ver int64, key []byte, val []byte, exp []byte) (kvs.KV, error) {
all, err := tx.pntr.PutC(uint64(ver), key, val, exp) res, err := tx.pntr.PutC(uint64(ver), key, val, exp)
return one(all, err) return one(res, err)
}
func (tx *TX) PutL(ver int64, key []byte, val []byte, max uint64) ([]kvs.KV, error) {
all, err := tx.pntr.PutL(uint64(ver), key, val, max)
out := make([]kvs.KV, len(all))
for i, v := range all {
out[i] = v
}
return many(out, err)
}
func (tx *TX) PutP(ver int64, key []byte, val []byte, max uint64) ([]kvs.KV, error) {
all, err := tx.pntr.PutP(uint64(ver), key, val, max)
out := make([]kvs.KV, len(all))
for i, v := range all {
out[i] = v
}
return many(out, err)
}
func (tx *TX) PutR(ver int64, beg []byte, end []byte, val []byte, max uint64) ([]kvs.KV, error) {
all, err := tx.pntr.PutR(uint64(ver), beg, end, val, max)
out := make([]kvs.KV, len(all))
for i, v := range all {
out[i] = v
}
return many(out, err)
} }

View file

@ -21,24 +21,18 @@ type TX interface {
Commit() error Commit() error
Clr([]byte) (KV, error) Clr([]byte) (KV, error)
ClrL([]byte, uint64) ([]KV, error)
ClrP([]byte, uint64) ([]KV, error) ClrP([]byte, uint64) ([]KV, error)
ClrR([]byte, []byte, uint64) ([]KV, error) ClrR([]byte, []byte, uint64) ([]KV, error)
Get(int64, []byte) (KV, error) Get(int64, []byte) (KV, error)
GetL(int64, []byte, uint64) ([]KV, error)
GetP(int64, []byte, uint64) ([]KV, error) GetP(int64, []byte, uint64) ([]KV, error)
GetR(int64, []byte, []byte, uint64) ([]KV, error) GetR(int64, []byte, []byte, uint64) ([]KV, error)
Del(int64, []byte) (KV, error) Del(int64, []byte) (KV, error)
DelC(int64, []byte, []byte) (KV, error) DelC(int64, []byte, []byte) (KV, error)
DelL(int64, []byte, uint64) ([]KV, error)
DelP(int64, []byte, uint64) ([]KV, error) DelP(int64, []byte, uint64) ([]KV, error)
DelR(int64, []byte, []byte, uint64) ([]KV, error) DelR(int64, []byte, []byte, uint64) ([]KV, error)
Put(int64, []byte, []byte) (KV, error) Put(int64, []byte, []byte) (KV, error)
PutC(int64, []byte, []byte, []byte) (KV, error) PutC(int64, []byte, []byte, []byte) (KV, error)
PutL(int64, []byte, []byte, uint64) ([]KV, error)
PutP(int64, []byte, []byte, uint64) ([]KV, error)
PutR(int64, []byte, []byte, []byte, uint64) ([]KV, error)
} }

View file

@ -78,7 +78,7 @@ func (c *Cache) AllNS() (out []*sql.DefineNamespaceStatement, err error) {
var kvs []kvs.KV var kvs []kvs.KV
key := &keys.NS{KV: cnf.Settings.DB.Base, NS: keys.Ignore} key := &keys.NS{KV: cnf.Settings.DB.Base, NS: keys.Ignore}
if kvs, err = c.TX.GetL(0, key.Encode(), 0); err != nil { if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil {
return return
} }
@ -163,7 +163,7 @@ func (c *Cache) AllNT(ns string) (out []*sql.DefineTokenStatement, err error) {
var kvs []kvs.KV var kvs []kvs.KV
key := &keys.NT{KV: cnf.Settings.DB.Base, NS: ns, TK: keys.Ignore} key := &keys.NT{KV: cnf.Settings.DB.Base, NS: ns, TK: keys.Ignore}
if kvs, err = c.TX.GetL(0, key.Encode(), 0); err != nil { if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil {
return return
} }
@ -204,7 +204,7 @@ func (c *Cache) AllNU(ns string) (out []*sql.DefineLoginStatement, err error) {
var kvs []kvs.KV var kvs []kvs.KV
key := &keys.NU{KV: cnf.Settings.DB.Base, NS: ns, US: keys.Ignore} key := &keys.NU{KV: cnf.Settings.DB.Base, NS: ns, US: keys.Ignore}
if kvs, err = c.TX.GetL(0, key.Encode(), 0); err != nil { if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil {
return return
} }
@ -251,7 +251,7 @@ func (c *Cache) AllDB(ns string) (out []*sql.DefineDatabaseStatement, err error)
var kvs []kvs.KV var kvs []kvs.KV
key := &keys.DB{KV: cnf.Settings.DB.Base, NS: ns, DB: keys.Ignore} key := &keys.DB{KV: cnf.Settings.DB.Base, NS: ns, DB: keys.Ignore}
if kvs, err = c.TX.GetL(0, key.Encode(), 0); err != nil { if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil {
return return
} }
@ -340,7 +340,7 @@ func (c *Cache) AllDT(ns, db string) (out []*sql.DefineTokenStatement, err error
var kvs []kvs.KV var kvs []kvs.KV
key := &keys.DT{KV: cnf.Settings.DB.Base, NS: ns, DB: db, TK: keys.Ignore} key := &keys.DT{KV: cnf.Settings.DB.Base, NS: ns, DB: db, TK: keys.Ignore}
if kvs, err = c.TX.GetL(0, key.Encode(), 0); err != nil { if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil {
return return
} }
@ -381,7 +381,7 @@ func (c *Cache) AllDU(ns, db string) (out []*sql.DefineLoginStatement, err error
var kvs []kvs.KV var kvs []kvs.KV
key := &keys.DU{KV: cnf.Settings.DB.Base, NS: ns, DB: db, US: keys.Ignore} key := &keys.DU{KV: cnf.Settings.DB.Base, NS: ns, DB: db, US: keys.Ignore}
if kvs, err = c.TX.GetL(0, key.Encode(), 0); err != nil { if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil {
return return
} }
@ -422,7 +422,7 @@ func (c *Cache) AllSC(ns, db string) (out []*sql.DefineScopeStatement, err error
var kvs []kvs.KV var kvs []kvs.KV
key := &keys.SC{KV: cnf.Settings.DB.Base, NS: ns, DB: db, SC: keys.Ignore} key := &keys.SC{KV: cnf.Settings.DB.Base, NS: ns, DB: db, SC: keys.Ignore}
if kvs, err = c.TX.GetL(0, key.Encode(), 0); err != nil { if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil {
return return
} }
@ -463,7 +463,7 @@ func (c *Cache) AllST(ns, db, sc string) (out []*sql.DefineTokenStatement, err e
var kvs []kvs.KV var kvs []kvs.KV
key := &keys.ST{KV: cnf.Settings.DB.Base, NS: ns, DB: db, SC: sc, TK: keys.Ignore} key := &keys.ST{KV: cnf.Settings.DB.Base, NS: ns, DB: db, SC: sc, TK: keys.Ignore}
if kvs, err = c.TX.GetL(0, key.Encode(), 0); err != nil { if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil {
return return
} }
@ -510,7 +510,7 @@ func (c *Cache) AllTB(ns, db string) (out []*sql.DefineTableStatement, err error
var kvs []kvs.KV var kvs []kvs.KV
key := &keys.TB{KV: cnf.Settings.DB.Base, NS: ns, DB: db, TB: keys.Ignore} key := &keys.TB{KV: cnf.Settings.DB.Base, NS: ns, DB: db, TB: keys.Ignore}
if kvs, err = c.TX.GetL(0, key.Encode(), 0); err != nil { if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil {
return return
} }
@ -607,7 +607,7 @@ func (c *Cache) AllEV(ns, db, tb string) (out []*sql.DefineEventStatement, err e
var kvs []kvs.KV var kvs []kvs.KV
key := &keys.EV{KV: cnf.Settings.DB.Base, NS: ns, DB: db, TB: tb, EV: keys.Ignore} key := &keys.EV{KV: cnf.Settings.DB.Base, NS: ns, DB: db, TB: tb, EV: keys.Ignore}
if kvs, err = c.TX.GetL(0, key.Encode(), 0); err != nil { if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil {
return return
} }
@ -674,7 +674,7 @@ func (c *Cache) AllFD(ns, db, tb string) (out []*sql.DefineFieldStatement, err e
var kvs []kvs.KV var kvs []kvs.KV
key := &keys.FD{KV: cnf.Settings.DB.Base, NS: ns, DB: db, TB: tb, FD: keys.Ignore} key := &keys.FD{KV: cnf.Settings.DB.Base, NS: ns, DB: db, TB: tb, FD: keys.Ignore}
if kvs, err = c.TX.GetL(0, key.Encode(), 0); err != nil { if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil {
return return
} }
@ -741,7 +741,7 @@ func (c *Cache) AllIX(ns, db, tb string) (out []*sql.DefineIndexStatement, err e
var kvs []kvs.KV var kvs []kvs.KV
key := &keys.IX{KV: cnf.Settings.DB.Base, NS: ns, DB: db, TB: tb, IX: keys.Ignore} key := &keys.IX{KV: cnf.Settings.DB.Base, NS: ns, DB: db, TB: tb, IX: keys.Ignore}
if kvs, err = c.TX.GetL(0, key.Encode(), 0); err != nil { if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil {
return return
} }
@ -808,7 +808,7 @@ func (c *Cache) AllFT(ns, db, tb string) (out []*sql.DefineTableStatement, err e
var kvs []kvs.KV var kvs []kvs.KV
key := &keys.FT{KV: cnf.Settings.DB.Base, NS: ns, DB: db, TB: tb, FT: keys.Ignore} key := &keys.FT{KV: cnf.Settings.DB.Base, NS: ns, DB: db, TB: tb, FT: keys.Ignore}
if kvs, err = c.TX.GetL(0, key.Encode(), 0); err != nil { if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil {
return return
} }
@ -875,7 +875,7 @@ func (c *Cache) AllLV(ns, db, tb string) (out []*sql.LiveStatement, err error) {
var kvs []kvs.KV var kvs []kvs.KV
key := &keys.LV{KV: cnf.Settings.DB.Base, NS: ns, DB: db, TB: tb, LV: keys.Ignore} key := &keys.LV{KV: cnf.Settings.DB.Base, NS: ns, DB: db, TB: tb, LV: keys.Ignore}
if kvs, err = c.TX.GetL(0, key.Encode(), 0); err != nil { if kvs, err = c.TX.GetP(0, key.Encode(), 0); err != nil {
return return
} }

55
util/keys/database.go Normal file
View file

@ -0,0 +1,55 @@
// Copyright © 2016 Abcum Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package keys
// Database ...
type Database struct {
KV string
NS string
DB string
}
// init initialises the key
func (k *Database) init() *Database {
return k
}
// Copy creates a copy of the key
func (k *Database) Copy() *Database {
return &Database{
KV: k.KV,
NS: k.NS,
DB: k.DB,
}
}
// Encode encodes the key into binary
func (k *Database) Encode() []byte {
k.init()
return encode(k.KV, "*", k.NS, "*", k.DB)
}
// Decode decodes the key from binary
func (k *Database) Decode(data []byte) {
k.init()
var __ string
decode(data, &k.KV, &__, &k.NS, &__, &k.DB)
}
// String returns a string representation of the key
func (k *Database) String() string {
k.init()
return output(k.KV, "*", k.NS, "*", k.DB)
}

View file

@ -38,18 +38,18 @@ func (k *DB) Copy() *DB {
// Encode encodes the key into binary // Encode encodes the key into binary
func (k *DB) Encode() []byte { func (k *DB) Encode() []byte {
k.init() k.init()
return encode(k.KV, k.NS, "*", k.DB) return encode(k.KV, "*", k.NS, "!", "d", k.DB)
} }
// Decode decodes the key from binary // Decode decodes the key from binary
func (k *DB) Decode(data []byte) { func (k *DB) Decode(data []byte) {
k.init() k.init()
var __ string var __ string
decode(data, &k.KV, &k.NS, &__, &k.DB) decode(data, &k.KV, &__, &k.NS, &__, &__, &k.DB)
} }
// String returns a string representation of the key // String returns a string representation of the key
func (k *DB) String() string { func (k *DB) String() string {
k.init() k.init()
return output(k.KV, k.NS, "*", k.DB) return output(k.KV, "*", k.NS, "!", "d", k.DB)
} }

View file

@ -40,18 +40,18 @@ func (k *DT) Copy() *DT {
// Encode encodes the key into binary // Encode encodes the key into binary
func (k *DT) Encode() []byte { func (k *DT) Encode() []byte {
k.init() k.init()
return encode(k.KV, k.NS, "*", k.DB, "!", "t", k.TK) return encode(k.KV, "*", k.NS, "*", k.DB, "!", "k", k.TK)
} }
// Decode decodes the key from binary // Decode decodes the key from binary
func (k *DT) Decode(data []byte) { func (k *DT) Decode(data []byte) {
k.init() k.init()
var __ string var __ string
decode(data, &k.KV, &k.NS, &__, &k.DB, &__, &__, &k.TK) decode(data, &k.KV, &__, &k.NS, &__, &k.DB, &__, &__, &k.TK)
} }
// String returns a string representation of the key // String returns a string representation of the key
func (k *DT) String() string { func (k *DT) String() string {
k.init() k.init()
return output(k.KV, k.NS, "*", k.DB, "!", "t", k.TK) return output(k.KV, "*", k.NS, "*", k.DB, "!", "k", k.TK)
} }

View file

@ -40,18 +40,18 @@ func (k *DU) Copy() *DU {
// Encode encodes the key into binary // Encode encodes the key into binary
func (k *DU) Encode() []byte { func (k *DU) Encode() []byte {
k.init() k.init()
return encode(k.KV, k.NS, "*", k.DB, "!", "u", k.US) return encode(k.KV, "*", k.NS, "*", k.DB, "!", "u", k.US)
} }
// Decode decodes the key from binary // Decode decodes the key from binary
func (k *DU) Decode(data []byte) { func (k *DU) Decode(data []byte) {
k.init() k.init()
var __ string var __ string
decode(data, &k.KV, &k.NS, &__, &k.DB, &__, &__, &k.US) decode(data, &k.KV, &__, &k.NS, &__, &k.DB, &__, &__, &k.US)
} }
// String returns a string representation of the key // String returns a string representation of the key
func (k *DU) String() string { func (k *DU) String() string {
k.init() k.init()
return output(k.KV, k.NS, "*", k.DB, "!", "u", k.US) return output(k.KV, "*", k.NS, "*", k.DB, "!", "u", k.US)
} }

View file

@ -57,18 +57,18 @@ func (k *Edge) Copy() *Edge {
// Encode encodes the key into binary // Encode encodes the key into binary
func (k *Edge) Encode() []byte { func (k *Edge) Encode() []byte {
k.init() k.init()
return encode(k.KV, k.NS, "*", k.DB, "*", k.TB, "*", k.ID, k.TK, k.TP, k.FT, k.FK) return encode(k.KV, "*", k.NS, "*", k.DB, "*", k.TB, "*", k.ID, k.TK, k.TP, k.FT, k.FK)
} }
// Decode decodes the key from binary // Decode decodes the key from binary
func (k *Edge) Decode(data []byte) { func (k *Edge) Decode(data []byte) {
k.init() k.init()
var __ string var __ string
decode(data, &k.KV, &k.NS, &__, &k.DB, &__, &k.TB, &__, &k.ID, &k.TK, &k.TP, &k.FT, &k.FK) decode(data, &k.KV, &__, &k.NS, &__, &k.DB, &__, &k.TB, &__, &k.ID, &k.TK, &k.TP, &k.FT, &k.FK)
} }
// String returns a string representation of the key // String returns a string representation of the key
func (k *Edge) String() string { func (k *Edge) String() string {
k.init() k.init()
return output(k.KV, k.NS, "*", k.DB, "*", k.TB, "*", k.ID, k.TK, k.TP, k.FT, k.FK) return output(k.KV, "*", k.NS, "*", k.DB, "*", k.TB, "*", k.ID, k.TK, k.TP, k.FT, k.FK)
} }

View file

@ -42,18 +42,18 @@ func (k *EV) Copy() *EV {
// Encode encodes the key into binary // Encode encodes the key into binary
func (k *EV) Encode() []byte { func (k *EV) Encode() []byte {
k.init() k.init()
return encode(k.KV, k.NS, "*", k.DB, "*", k.TB, "!", "e", k.EV) return encode(k.KV, "*", k.NS, "*", k.DB, "*", k.TB, "!", "e", k.EV)
} }
// Decode decodes the key from binary // Decode decodes the key from binary
func (k *EV) Decode(data []byte) { func (k *EV) Decode(data []byte) {
k.init() k.init()
var __ string var __ string
decode(data, &k.KV, &k.NS, &__, &k.DB, &__, &k.TB, &__, &__, &k.EV) decode(data, &k.KV, &__, &k.NS, &__, &k.DB, &__, &k.TB, &__, &__, &k.EV)
} }
// String returns a string representation of the key // String returns a string representation of the key
func (k *EV) String() string { func (k *EV) String() string {
k.init() k.init()
return output(k.KV, k.NS, "*", k.DB, "*", k.TB, "!", "e", k.EV) return output(k.KV, "*", k.NS, "*", k.DB, "*", k.TB, "!", "e", k.EV)
} }

View file

@ -42,18 +42,18 @@ func (k *FD) Copy() *FD {
// Encode encodes the key into binary // Encode encodes the key into binary
func (k *FD) Encode() []byte { func (k *FD) Encode() []byte {
k.init() k.init()
return encode(k.KV, k.NS, "*", k.DB, "*", k.TB, "!", "f", k.FD) return encode(k.KV, "*", k.NS, "*", k.DB, "*", k.TB, "!", "f", k.FD)
} }
// Decode decodes the key from binary // Decode decodes the key from binary
func (k *FD) Decode(data []byte) { func (k *FD) Decode(data []byte) {
k.init() k.init()
var __ string var __ string
decode(data, &k.KV, &k.NS, &__, &k.DB, &__, &k.TB, &__, &__, &k.FD) decode(data, &k.KV, &__, &k.NS, &__, &k.DB, &__, &k.TB, &__, &__, &k.FD)
} }
// String returns a string representation of the key // String returns a string representation of the key
func (k *FD) String() string { func (k *FD) String() string {
k.init() k.init()
return output(k.KV, k.NS, "*", k.DB, "*", k.TB, "!", "f", k.FD) return output(k.KV, "*", k.NS, "*", k.DB, "*", k.TB, "!", "f", k.FD)
} }

View file

@ -44,18 +44,18 @@ func (k *Field) Copy() *Field {
// Encode encodes the key into binary // Encode encodes the key into binary
func (k *Field) Encode() []byte { func (k *Field) Encode() []byte {
k.init() k.init()
return encode(k.KV, k.NS, "*", k.DB, "*", k.TB, "*", k.ID, "*", k.FD) return encode(k.KV, "*", k.NS, "*", k.DB, "*", k.TB, "*", k.ID, "*", k.FD)
} }
// Decode decodes the key from binary // Decode decodes the key from binary
func (k *Field) Decode(data []byte) { func (k *Field) Decode(data []byte) {
k.init() k.init()
var __ string var __ string
decode(data, &k.KV, &k.NS, &__, &k.DB, &__, &k.TB, &__, &k.ID, &__, &k.FD) decode(data, &k.KV, &__, &k.NS, &__, &k.DB, &__, &k.TB, &__, &k.ID, &__, &k.FD)
} }
// String returns a string representation of the key // String returns a string representation of the key
func (k *Field) String() string { func (k *Field) String() string {
k.init() k.init()
return output(k.KV, k.NS, "*", k.DB, "*", k.TB, "*", k.ID, "*", k.FD) return output(k.KV, "*", k.NS, "*", k.DB, "*", k.TB, "*", k.ID, "*", k.FD)
} }

View file

@ -41,18 +41,18 @@ func (k *FT) Copy() *FT {
// Encode encodes the key into binary // Encode encodes the key into binary
func (k *FT) Encode() []byte { func (k *FT) Encode() []byte {
k.init() k.init()
return encode(k.KV, k.NS, "*", k.DB, "*", k.TB, "!", "t", k.FT) return encode(k.KV, "*", k.NS, "*", k.DB, "*", k.TB, "!", "t", k.FT)
} }
// Decode decodes the key from binary // Decode decodes the key from binary
func (k *FT) Decode(data []byte) { func (k *FT) Decode(data []byte) {
k.init() k.init()
var __ string var __ string
decode(data, &k.KV, &k.NS, &__, &k.DB, &__, &k.TB, &__, &__, &k.FT) decode(data, &k.KV, &__, &k.NS, &__, &k.DB, &__, &k.TB, &__, &__, &k.FT)
} }
// String returns a string representation of the key // String returns a string representation of the key
func (k *FT) String() string { func (k *FT) String() string {
k.init() k.init()
return output(k.KV, k.NS, "*", k.DB, "*", k.TB, "!", "t", k.FT) return output(k.KV, "*", k.NS, "*", k.DB, "*", k.TB, "!", "t", k.FT)
} }

View file

@ -44,18 +44,18 @@ func (k *Index) Copy() *Index {
// Encode encodes the key into binary // Encode encodes the key into binary
func (k *Index) Encode() []byte { func (k *Index) Encode() []byte {
k.init() k.init()
return encode(k.KV, k.NS, "*", k.DB, "*", k.TB, "¤", k.IX, k.FD) return encode(k.KV, "*", k.NS, "*", k.DB, "*", k.TB, "¤", k.IX, k.FD)
} }
// Decode decodes the key from binary // Decode decodes the key from binary
func (k *Index) Decode(data []byte) { func (k *Index) Decode(data []byte) {
k.init() k.init()
var __ string var __ string
decode(data, &k.KV, &k.NS, &__, &k.DB, &__, &k.TB, &__, &k.IX, &k.FD) decode(data, &k.KV, &__, &k.NS, &__, &k.DB, &__, &k.TB, &__, &k.IX, &k.FD)
} }
// String returns a string representation of the key // String returns a string representation of the key
func (k *Index) String() string { func (k *Index) String() string {
k.init() k.init()
return output(k.KV, k.NS, "*", k.DB, "*", k.TB, "¤", k.IX, k.FD) return output(k.KV, "*", k.NS, "*", k.DB, "*", k.TB, "¤", k.IX, k.FD)
} }

View file

@ -42,18 +42,18 @@ func (k *IX) Copy() *IX {
// Encode encodes the key into binary // Encode encodes the key into binary
func (k *IX) Encode() []byte { func (k *IX) Encode() []byte {
k.init() k.init()
return encode(k.KV, k.NS, "*", k.DB, "*", k.TB, "!", "i", k.IX) return encode(k.KV, "*", k.NS, "*", k.DB, "*", k.TB, "!", "i", k.IX)
} }
// Decode decodes the key from binary // Decode decodes the key from binary
func (k *IX) Decode(data []byte) { func (k *IX) Decode(data []byte) {
k.init() k.init()
var __ string var __ string
decode(data, &k.KV, &k.NS, &__, &k.DB, &__, &k.TB, &__, &__, &k.IX) decode(data, &k.KV, &__, &k.NS, &__, &k.DB, &__, &k.TB, &__, &__, &k.IX)
} }
// String returns a string representation of the key // String returns a string representation of the key
func (k *IX) String() string { func (k *IX) String() string {
k.init() k.init()
return output(k.KV, k.NS, "*", k.DB, "*", k.TB, "!", "i", k.IX) return output(k.KV, "*", k.NS, "*", k.DB, "*", k.TB, "!", "i", k.IX)
} }

View file

@ -86,152 +86,162 @@ func TestMain(t *testing.T) {
new: &KV{}, new: &KV{},
}, },
{ {
str: "/surreal/abcum", str: "/surreal/!/n/abcum",
obj: &NS{KV: "surreal", NS: "abcum"}, obj: &NS{KV: "surreal", NS: "abcum"},
new: &NS{}, new: &NS{},
}, },
{ {
str: "/surreal/abcum/!/t/default", str: "/surreal/*/abcum",
obj: &NT{KV: "surreal", NS: "abcum", TK: "default"}, obj: &Namespace{KV: "surreal", NS: "abcum"},
new: &NT{}, new: &Namespace{},
}, },
{ {
str: "/surreal/abcum/!/u/info@abcum.com", str: "/surreal/*/abcum/!/d/database",
obj: &NU{KV: "surreal", NS: "abcum", US: "info@abcum.com"},
new: &NU{},
},
{
str: "/surreal/abcum/*/database",
obj: &DB{KV: "surreal", NS: "abcum", DB: "database"}, obj: &DB{KV: "surreal", NS: "abcum", DB: "database"},
new: &DB{}, new: &DB{},
}, },
{ {
str: "/surreal/abcum/*/database/!/s/admin", str: "/surreal/*/abcum/!/k/default",
obj: &SC{KV: "surreal", NS: "abcum", DB: "database", SC: "admin"}, obj: &NT{KV: "surreal", NS: "abcum", TK: "default"},
new: &SC{}, new: &NT{},
}, },
{ {
str: "/surreal/abcum/*/database/!/s/admin/!/t/default", str: "/surreal/*/abcum/!/u/info@abcum.com",
obj: &ST{KV: "surreal", NS: "abcum", DB: "database", SC: "admin", TK: "default"}, obj: &NU{KV: "surreal", NS: "abcum", US: "info@abcum.com"},
new: &ST{}, new: &NU{},
}, },
{ {
str: "/surreal/abcum/*/database/!/t/default", str: "/surreal/*/abcum/*/database",
obj: &Database{KV: "surreal", NS: "abcum", DB: "database"},
new: &Database{},
},
{
str: "/surreal/*/abcum/*/database/!/k/default",
obj: &DT{KV: "surreal", NS: "abcum", DB: "database", TK: "default"}, obj: &DT{KV: "surreal", NS: "abcum", DB: "database", TK: "default"},
new: &DT{}, new: &DT{},
}, },
{ {
str: "/surreal/abcum/*/database/!/u/info@abcum.com", str: "/surreal/*/abcum/*/database/!/s/admin",
obj: &DU{KV: "surreal", NS: "abcum", DB: "database", US: "info@abcum.com"}, obj: &SC{KV: "surreal", NS: "abcum", DB: "database", SC: "admin"},
new: &DU{}, new: &SC{},
}, },
{ {
str: "/surreal/abcum/*/database/*/person", str: "/surreal/*/abcum/*/database/!/s/admin/!/k/default",
obj: &ST{KV: "surreal", NS: "abcum", DB: "database", SC: "admin", TK: "default"},
new: &ST{},
},
{
str: "/surreal/*/abcum/*/database/!/t/person",
obj: &TB{KV: "surreal", NS: "abcum", DB: "database", TB: "person"}, obj: &TB{KV: "surreal", NS: "abcum", DB: "database", TB: "person"},
new: &TB{}, new: &TB{},
}, },
{ {
str: "/surreal/abcum/*/database/*/person/!/e/trigger", str: "/surreal/*/abcum/*/database/!/u/info@abcum.com",
obj: &EV{KV: "surreal", NS: "abcum", DB: "database", TB: "person", EV: "trigger"}, obj: &DU{KV: "surreal", NS: "abcum", DB: "database", US: "info@abcum.com"},
new: &EV{}, new: &DU{},
}, },
{ {
str: "/surreal/abcum/*/database/*/person/!/f/fullname", str: "/surreal/*/abcum/*/database/*/person",
obj: &FD{KV: "surreal", NS: "abcum", DB: "database", TB: "person", FD: "fullname"},
new: &FD{},
},
{
str: "/surreal/abcum/*/database/*/person/!/i/teenagers",
obj: &IX{KV: "surreal", NS: "abcum", DB: "database", TB: "person", IX: "teenagers"},
new: &IX{},
},
{
str: "/surreal/abcum/*/database/*/person/!/l/realtime",
obj: &LV{KV: "surreal", NS: "abcum", DB: "database", TB: "person", LV: "realtime"},
new: &LV{},
},
{
str: "/surreal/abcum/*/database/*/person/!/t/foreign",
obj: &FT{KV: "surreal", NS: "abcum", DB: "database", TB: "person", FT: "foreign"},
new: &FT{},
},
{
str: "/surreal/abcum/*/database/*/person/*",
obj: &Table{KV: "surreal", NS: "abcum", DB: "database", TB: "person"}, obj: &Table{KV: "surreal", NS: "abcum", DB: "database", TB: "person"},
new: &Table{}, new: &Table{},
}, },
{ {
str: "/surreal/abcum/*/database/*/person/*/\x01", str: "/surreal/*/abcum/*/database/*/person/!/e/trigger",
obj: &EV{KV: "surreal", NS: "abcum", DB: "database", TB: "person", EV: "trigger"},
new: &EV{},
},
{
str: "/surreal/*/abcum/*/database/*/person/!/f/fullname",
obj: &FD{KV: "surreal", NS: "abcum", DB: "database", TB: "person", FD: "fullname"},
new: &FD{},
},
{
str: "/surreal/*/abcum/*/database/*/person/!/i/teenagers",
obj: &IX{KV: "surreal", NS: "abcum", DB: "database", TB: "person", IX: "teenagers"},
new: &IX{},
},
{
str: "/surreal/*/abcum/*/database/*/person/!/l/realtime",
obj: &LV{KV: "surreal", NS: "abcum", DB: "database", TB: "person", LV: "realtime"},
new: &LV{},
},
{
str: "/surreal/*/abcum/*/database/*/person/!/t/foreign",
obj: &FT{KV: "surreal", NS: "abcum", DB: "database", TB: "person", FT: "foreign"},
new: &FT{},
},
{
str: "/surreal/*/abcum/*/database/*/person/*/\x01",
obj: &Thing{KV: "surreal", NS: "abcum", DB: "database", TB: "person", ID: Prefix}, obj: &Thing{KV: "surreal", NS: "abcum", DB: "database", TB: "person", ID: Prefix},
new: &Thing{}, new: &Thing{},
}, },
{ {
str: "/surreal/abcum/*/database/*/person/*/873c2f37-ea03-4c5e-843e-cf393af44155", str: "/surreal/*/abcum/*/database/*/person/*/873c2f37-ea03-4c5e-843e-cf393af44155",
obj: &Thing{KV: "surreal", NS: "abcum", DB: "database", TB: "person", ID: "873c2f37-ea03-4c5e-843e-cf393af44155"}, obj: &Thing{KV: "surreal", NS: "abcum", DB: "database", TB: "person", ID: "873c2f37-ea03-4c5e-843e-cf393af44155"},
new: &Thing{}, new: &Thing{},
}, },
{ {
str: "/surreal/abcum/*/database/*/person/*/873c2f37-ea03-4c5e-843e-cf393af44155/*/name.first", str: "/surreal/*/abcum/*/database/*/person/*/873c2f37-ea03-4c5e-843e-cf393af44155/*/name.first",
obj: &Field{KV: "surreal", NS: "abcum", DB: "database", TB: "person", ID: "873c2f37-ea03-4c5e-843e-cf393af44155", FD: "name.first"}, obj: &Field{KV: "surreal", NS: "abcum", DB: "database", TB: "person", ID: "873c2f37-ea03-4c5e-843e-cf393af44155", FD: "name.first"},
new: &Field{}, new: &Field{},
}, },
{ {
str: "/surreal/abcum/*/database/*/person/*/873c2f37-ea03-4c5e-843e-cf393af44155/*/name.last", str: "/surreal/*/abcum/*/database/*/person/*/873c2f37-ea03-4c5e-843e-cf393af44155/*/name.last",
obj: &Field{KV: "surreal", NS: "abcum", DB: "database", TB: "person", ID: "873c2f37-ea03-4c5e-843e-cf393af44155", FD: "name.last"}, obj: &Field{KV: "surreal", NS: "abcum", DB: "database", TB: "person", ID: "873c2f37-ea03-4c5e-843e-cf393af44155", FD: "name.last"},
new: &Field{}, new: &Field{},
}, },
{ {
str: "/surreal/abcum/*/database/*/person/*/873c2f37-ea03-4c5e-843e-cf393af44155/«/clicked/link/b38d7aa1-60d6-4f2d-8702-46bd0fa961fe", str: "/surreal/*/abcum/*/database/*/person/*/873c2f37-ea03-4c5e-843e-cf393af44155/«/clicked/link/b38d7aa1-60d6-4f2d-8702-46bd0fa961fe",
obj: &Edge{KV: "surreal", NS: "abcum", DB: "database", TB: "person", ID: "873c2f37-ea03-4c5e-843e-cf393af44155", TK: "«", TP: "clicked", FT: "link", FK: "b38d7aa1-60d6-4f2d-8702-46bd0fa961fe"}, obj: &Edge{KV: "surreal", NS: "abcum", DB: "database", TB: "person", ID: "873c2f37-ea03-4c5e-843e-cf393af44155", TK: "«", TP: "clicked", FT: "link", FK: "b38d7aa1-60d6-4f2d-8702-46bd0fa961fe"},
new: &Edge{}, new: &Edge{},
}, },
{ {
str: "/surreal/abcum/*/database/*/person/*/873c2f37-ea03-4c5e-843e-cf393af44155/«»/clicked/link/b38d7aa1-60d6-4f2d-8702-46bd0fa961fe", str: "/surreal/*/abcum/*/database/*/person/*/873c2f37-ea03-4c5e-843e-cf393af44155/«»/clicked/link/b38d7aa1-60d6-4f2d-8702-46bd0fa961fe",
obj: &Edge{KV: "surreal", NS: "abcum", DB: "database", TB: "person", ID: "873c2f37-ea03-4c5e-843e-cf393af44155", TK: "«»", TP: "clicked", FT: "link", FK: "b38d7aa1-60d6-4f2d-8702-46bd0fa961fe"}, obj: &Edge{KV: "surreal", NS: "abcum", DB: "database", TB: "person", ID: "873c2f37-ea03-4c5e-843e-cf393af44155", TK: "«»", TP: "clicked", FT: "link", FK: "b38d7aa1-60d6-4f2d-8702-46bd0fa961fe"},
new: &Edge{}, new: &Edge{},
}, },
{ {
str: "/surreal/abcum/*/database/*/person/*/873c2f37-ea03-4c5e-843e-cf393af44155/»/clicked/link/b38d7aa1-60d6-4f2d-8702-46bd0fa961fe", str: "/surreal/*/abcum/*/database/*/person/*/873c2f37-ea03-4c5e-843e-cf393af44155/»/clicked/link/b38d7aa1-60d6-4f2d-8702-46bd0fa961fe",
obj: &Edge{KV: "surreal", NS: "abcum", DB: "database", TB: "person", ID: "873c2f37-ea03-4c5e-843e-cf393af44155", TK: "»", TP: "clicked", FT: "link", FK: "b38d7aa1-60d6-4f2d-8702-46bd0fa961fe"}, obj: &Edge{KV: "surreal", NS: "abcum", DB: "database", TB: "person", ID: "873c2f37-ea03-4c5e-843e-cf393af44155", TK: "»", TP: "clicked", FT: "link", FK: "b38d7aa1-60d6-4f2d-8702-46bd0fa961fe"},
new: &Edge{}, new: &Edge{},
}, },
{ {
str: "/surreal/abcum/*/database/*/person/*/\xff", str: "/surreal/*/abcum/*/database/*/person/*/\xff",
obj: &Thing{KV: "surreal", NS: "abcum", DB: "database", TB: "person", ID: Suffix}, obj: &Thing{KV: "surreal", NS: "abcum", DB: "database", TB: "person", ID: Suffix},
new: &Thing{}, new: &Thing{},
}, },
{ {
str: "/surreal/abcum/*/database/*/person/~/873c2f37-ea03-4c5e-843e-cf393af44155/1987-06-22T08:00:00.123456789Z", str: "/surreal/*/abcum/*/database/*/person/~/873c2f37-ea03-4c5e-843e-cf393af44155/1987-06-22T08:00:00.123456789Z",
obj: &Patch{KV: "surreal", NS: "abcum", DB: "database", TB: "person", ID: "873c2f37-ea03-4c5e-843e-cf393af44155", AT: clock}, obj: &Patch{KV: "surreal", NS: "abcum", DB: "database", TB: "person", ID: "873c2f37-ea03-4c5e-843e-cf393af44155", AT: clock},
new: &Patch{}, new: &Patch{},
}, },
{ {
str: "/surreal/abcum/*/database/*/person/~/test/1987-06-22T08:00:00.123456789Z", str: "/surreal/*/abcum/*/database/*/person/~/test/1987-06-22T08:00:00.123456789Z",
obj: &Patch{KV: "surreal", NS: "abcum", DB: "database", TB: "person", ID: "test", AT: clock}, obj: &Patch{KV: "surreal", NS: "abcum", DB: "database", TB: "person", ID: "test", AT: clock},
new: &Patch{}, new: &Patch{},
}, },
{ {
str: "/surreal/abcum/*/database/*/person/¤/names/[false account:1 lastname <nil> firstname]", str: "/surreal/*/abcum/*/database/*/person/¤/names/[false account:1 lastname <nil> firstname]",
obj: &Index{KV: "surreal", NS: "abcum", DB: "database", TB: "person", IX: "names", FD: []interface{}{false, "account:1", "lastname", nil, "firstname"}}, obj: &Index{KV: "surreal", NS: "abcum", DB: "database", TB: "person", IX: "names", FD: []interface{}{false, "account:1", "lastname", nil, "firstname"}},
new: &Index{}, new: &Index{},
}, },
{ {
str: "/surreal/abcum/*/database/*/person/¤/names/[lastname firstname]", str: "/surreal/*/abcum/*/database/*/person/¤/names/[lastname firstname]",
obj: &Index{KV: "surreal", NS: "abcum", DB: "database", TB: "person", IX: "names", FD: []interface{}{"lastname", "firstname"}}, obj: &Index{KV: "surreal", NS: "abcum", DB: "database", TB: "person", IX: "names", FD: []interface{}{"lastname", "firstname"}},
new: &Index{}, new: &Index{},
}, },
{ {
str: "/surreal/abcum/*/database/*/person/¤/names/[lastname firstname]/873c2f37-ea03-4c5e-843e-cf393af44155", str: "/surreal/*/abcum/*/database/*/person/¤/names/[lastname firstname]/873c2f37-ea03-4c5e-843e-cf393af44155",
obj: &Point{KV: "surreal", NS: "abcum", DB: "database", TB: "person", IX: "names", FD: []interface{}{"lastname", "firstname"}, ID: "873c2f37-ea03-4c5e-843e-cf393af44155"}, obj: &Point{KV: "surreal", NS: "abcum", DB: "database", TB: "person", IX: "names", FD: []interface{}{"lastname", "firstname"}, ID: "873c2f37-ea03-4c5e-843e-cf393af44155"},
new: &Point{}, new: &Point{},
}, },
{ {
str: "/surreal/abcum/*/database/*/person/¤/uniqs/[false account:1 lastname <nil> firstname]/873c2f37-ea03-4c5e-843e-cf393af44155", str: "/surreal/*/abcum/*/database/*/person/¤/uniqs/[false account:1 lastname <nil> firstname]/873c2f37-ea03-4c5e-843e-cf393af44155",
obj: &Point{KV: "surreal", NS: "abcum", DB: "database", TB: "person", IX: "uniqs", FD: []interface{}{false, "account:1", "lastname", nil, "firstname"}, ID: "873c2f37-ea03-4c5e-843e-cf393af44155"}, obj: &Point{KV: "surreal", NS: "abcum", DB: "database", TB: "person", IX: "uniqs", FD: []interface{}{false, "account:1", "lastname", nil, "firstname"}, ID: "873c2f37-ea03-4c5e-843e-cf393af44155"},
new: &Point{}, new: &Point{},
}, },
{ {
str: "/surreal/abcum/*/database/*/person/¤/uniqs/[lastname firstname]/873c2f37-ea03-4c5e-843e-cf393af44155", str: "/surreal/*/abcum/*/database/*/person/¤/uniqs/[lastname firstname]/873c2f37-ea03-4c5e-843e-cf393af44155",
obj: &Point{KV: "surreal", NS: "abcum", DB: "database", TB: "person", IX: "uniqs", FD: []interface{}{"lastname", "firstname"}, ID: "873c2f37-ea03-4c5e-843e-cf393af44155"}, obj: &Point{KV: "surreal", NS: "abcum", DB: "database", TB: "person", IX: "uniqs", FD: []interface{}{"lastname", "firstname"}, ID: "873c2f37-ea03-4c5e-843e-cf393af44155"},
new: &Point{}, new: &Point{},
}, },
@ -368,8 +378,26 @@ func TestMain(t *testing.T) {
nos []Key nos []Key
}{ }{
{ {
obj: &TB{KV: "kv", NS: "ns", DB: "db", TB: "person"}, obj: &Namespace{KV: "kv", NS: "ns"},
yes: []Key{ yes: []Key{
&Thing{KV: "kv", NS: "ns", DB: "other", TB: "person", ID: "test"},
&Table{KV: "kv", NS: "ns", DB: "db", TB: "person"},
&Thing{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: Prefix},
&Thing{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: "test"},
&Thing{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: Suffix},
&Patch{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: "test", AT: clock},
&Index{KV: "kv", NS: "ns", DB: "db", TB: "person", IX: "names", FD: []interface{}{"1", "2"}},
&Point{KV: "kv", NS: "ns", DB: "db", TB: "person", IX: "names", FD: []interface{}{"3", "4"}},
},
nos: []Key{
&Thing{KV: "kv", NS: "other", DB: "db", TB: "person", ID: "test"},
&Thing{KV: "other", NS: "ns", DB: "db", TB: "person", ID: "test"},
},
},
{
obj: &Database{KV: "kv", NS: "ns", DB: "db"},
yes: []Key{
&Table{KV: "kv", NS: "ns", DB: "db", TB: "person"},
&Thing{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: Prefix}, &Thing{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: Prefix},
&Thing{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: "test"}, &Thing{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: "test"},
&Thing{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: Suffix}, &Thing{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: Suffix},
@ -378,7 +406,6 @@ func TestMain(t *testing.T) {
&Point{KV: "kv", NS: "ns", DB: "db", TB: "person", IX: "names", FD: []interface{}{"3", "4"}}, &Point{KV: "kv", NS: "ns", DB: "db", TB: "person", IX: "names", FD: []interface{}{"3", "4"}},
}, },
nos: []Key{ nos: []Key{
&Thing{KV: "kv", NS: "ns", DB: "db", TB: "other", ID: "test"},
&Thing{KV: "kv", NS: "ns", DB: "other", TB: "person", ID: "test"}, &Thing{KV: "kv", NS: "ns", DB: "other", TB: "person", ID: "test"},
&Thing{KV: "kv", NS: "other", DB: "db", TB: "person", ID: "test"}, &Thing{KV: "kv", NS: "other", DB: "db", TB: "person", ID: "test"},
&Thing{KV: "other", NS: "ns", DB: "db", TB: "person", ID: "test"}, &Thing{KV: "other", NS: "ns", DB: "db", TB: "person", ID: "test"},
@ -390,15 +417,15 @@ func TestMain(t *testing.T) {
&Thing{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: Prefix}, &Thing{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: Prefix},
&Thing{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: "test"}, &Thing{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: "test"},
&Thing{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: Suffix}, &Thing{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: Suffix},
&Patch{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: "test", AT: clock},
&Index{KV: "kv", NS: "ns", DB: "db", TB: "person", IX: "names", FD: []interface{}{"1", "2"}},
&Point{KV: "kv", NS: "ns", DB: "db", TB: "person", IX: "names", FD: []interface{}{"3", "4"}},
}, },
nos: []Key{ nos: []Key{
&Thing{KV: "kv", NS: "ns", DB: "db", TB: "other", ID: "test"}, &Thing{KV: "kv", NS: "ns", DB: "db", TB: "other", ID: "test"},
&Thing{KV: "kv", NS: "ns", DB: "other", TB: "person", ID: "test"}, &Thing{KV: "kv", NS: "ns", DB: "other", TB: "person", ID: "test"},
&Thing{KV: "kv", NS: "other", DB: "db", TB: "person", ID: "test"}, &Thing{KV: "kv", NS: "other", DB: "db", TB: "person", ID: "test"},
&Thing{KV: "other", NS: "ns", DB: "db", TB: "person", ID: "test"}, &Thing{KV: "other", NS: "ns", DB: "db", TB: "person", ID: "test"},
&Patch{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: "test", AT: clock},
&Index{KV: "kv", NS: "ns", DB: "db", TB: "person", IX: "names", FD: []interface{}{"1", "2"}},
&Point{KV: "kv", NS: "ns", DB: "db", TB: "person", IX: "names", FD: []interface{}{"3", "4"}},
}, },
}, },
{ {

View file

@ -42,18 +42,18 @@ func (k *LV) Copy() *LV {
// Encode encodes the key into binary // Encode encodes the key into binary
func (k *LV) Encode() []byte { func (k *LV) Encode() []byte {
k.init() k.init()
return encode(k.KV, k.NS, "*", k.DB, "*", k.TB, "!", "l", k.LV) return encode(k.KV, "*", k.NS, "*", k.DB, "*", k.TB, "!", "l", k.LV)
} }
// Decode decodes the key from binary // Decode decodes the key from binary
func (k *LV) Decode(data []byte) { func (k *LV) Decode(data []byte) {
k.init() k.init()
var __ string var __ string
decode(data, &k.KV, &k.NS, &__, &k.DB, &__, &k.TB, &__, &__, &k.LV) decode(data, &k.KV, &__, &k.NS, &__, &k.DB, &__, &k.TB, &__, &__, &k.LV)
} }
// String returns a string representation of the key // String returns a string representation of the key
func (k *LV) String() string { func (k *LV) String() string {
k.init() k.init()
return output(k.KV, k.NS, "*", k.DB, "*", k.TB, "!", "l", k.LV) return output(k.KV, "*", k.NS, "*", k.DB, "*", k.TB, "!", "l", k.LV)
} }

53
util/keys/namespace.go Normal file
View file

@ -0,0 +1,53 @@
// Copyright © 2016 Abcum Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package keys
// Namespace ...
type Namespace struct {
KV string
NS string
}
// init initialises the key
func (k *Namespace) init() *Namespace {
return k
}
// Copy creates a copy of the key
func (k *Namespace) Copy() *Namespace {
return &Namespace{
KV: k.KV,
NS: k.NS,
}
}
// Encode encodes the key into binary
func (k *Namespace) Encode() []byte {
k.init()
return encode(k.KV, "*", k.NS)
}
// Decode decodes the key from binary
func (k *Namespace) Decode(data []byte) {
k.init()
var __ string
decode(data, &k.KV, &__, &k.NS)
}
// String returns a string representation of the key
func (k *Namespace) String() string {
k.init()
return output(k.KV, "*", k.NS)
}

View file

@ -36,17 +36,18 @@ func (k *NS) Copy() *NS {
// Encode encodes the key into binary // Encode encodes the key into binary
func (k *NS) Encode() []byte { func (k *NS) Encode() []byte {
k.init() k.init()
return encode(k.KV, k.NS) return encode(k.KV, "!", "n", k.NS)
} }
// Decode decodes the key from binary // Decode decodes the key from binary
func (k *NS) Decode(data []byte) { func (k *NS) Decode(data []byte) {
k.init() k.init()
decode(data, &k.KV, &k.NS) var __ string
decode(data, &k.KV, &__, &__, &k.NS)
} }
// String returns a string representation of the key // String returns a string representation of the key
func (k *NS) String() string { func (k *NS) String() string {
k.init() k.init()
return output(k.KV, k.NS) return output(k.KV, "!", "n", k.NS)
} }

View file

@ -38,18 +38,18 @@ func (k *NT) Copy() *NT {
// Encode encodes the key into binary // Encode encodes the key into binary
func (k *NT) Encode() []byte { func (k *NT) Encode() []byte {
k.init() k.init()
return encode(k.KV, k.NS, "!", "t", k.TK) return encode(k.KV, "*", k.NS, "!", "k", k.TK)
} }
// Decode decodes the key from binary // Decode decodes the key from binary
func (k *NT) Decode(data []byte) { func (k *NT) Decode(data []byte) {
k.init() k.init()
var __ string var __ string
decode(data, &k.KV, &k.NS, &__, &__, &k.TK) decode(data, &k.KV, &__, &k.NS, &__, &__, &k.TK)
} }
// String returns a string representation of the key // String returns a string representation of the key
func (k *NT) String() string { func (k *NT) String() string {
k.init() k.init()
return output(k.KV, k.NS, "!", "t", k.TK) return output(k.KV, "*", k.NS, "!", "k", k.TK)
} }

View file

@ -38,18 +38,18 @@ func (k *NU) Copy() *NU {
// Encode encodes the key into binary // Encode encodes the key into binary
func (k *NU) Encode() []byte { func (k *NU) Encode() []byte {
k.init() k.init()
return encode(k.KV, k.NS, "!", "u", k.US) return encode(k.KV, "*", k.NS, "!", "u", k.US)
} }
// Decode decodes the key from binary // Decode decodes the key from binary
func (k *NU) Decode(data []byte) { func (k *NU) Decode(data []byte) {
k.init() k.init()
var __ string var __ string
decode(data, &k.KV, &k.NS, &__, &__, &k.US) decode(data, &k.KV, &__, &k.NS, &__, &__, &k.US)
} }
// String returns a string representation of the key // String returns a string representation of the key
func (k *NU) String() string { func (k *NU) String() string {
k.init() k.init()
return output(k.KV, k.NS, "!", "u", k.US) return output(k.KV, "*", k.NS, "!", "u", k.US)
} }

View file

@ -51,18 +51,18 @@ func (k *Patch) Copy() *Patch {
// Encode encodes the key into binary // Encode encodes the key into binary
func (k *Patch) Encode() []byte { func (k *Patch) Encode() []byte {
k.init() k.init()
return encode(k.KV, k.NS, "*", k.DB, "*", k.TB, "~", k.ID, k.AT) return encode(k.KV, "*", k.NS, "*", k.DB, "*", k.TB, "~", k.ID, k.AT)
} }
// Decode decodes the key from binary // Decode decodes the key from binary
func (k *Patch) Decode(data []byte) { func (k *Patch) Decode(data []byte) {
k.init() k.init()
var __ string var __ string
decode(data, &k.KV, &k.NS, &__, &k.DB, &__, &k.TB, &__, &k.ID, &k.AT) decode(data, &k.KV, &__, &k.NS, &__, &k.DB, &__, &k.TB, &__, &k.ID, &k.AT)
} }
// String returns a string representation of the key // String returns a string representation of the key
func (k *Patch) String() string { func (k *Patch) String() string {
k.init() k.init()
return output(k.KV, k.NS, "*", k.DB, "*", k.TB, "~", k.ID, k.AT.Format(time.RFC3339Nano)) return output(k.KV, "*", k.NS, "*", k.DB, "*", k.TB, "~", k.ID, k.AT.Format(time.RFC3339Nano))
} }

View file

@ -46,18 +46,18 @@ func (k *Point) Copy() *Point {
// Encode encodes the key into binary // Encode encodes the key into binary
func (k *Point) Encode() []byte { func (k *Point) Encode() []byte {
k.init() k.init()
return encode(k.KV, k.NS, "*", k.DB, "*", k.TB, "¤", k.IX, k.FD, k.ID) return encode(k.KV, "*", k.NS, "*", k.DB, "*", k.TB, "¤", k.IX, k.FD, k.ID)
} }
// Decode decodes the key from binary // Decode decodes the key from binary
func (k *Point) Decode(data []byte) { func (k *Point) Decode(data []byte) {
k.init() k.init()
var __ string var __ string
decode(data, &k.KV, &k.NS, &__, &k.DB, &__, &k.TB, &__, &k.IX, &k.FD, &k.ID) decode(data, &k.KV, &__, &k.NS, &__, &k.DB, &__, &k.TB, &__, &k.IX, &k.FD, &k.ID)
} }
// String returns a string representation of the key // String returns a string representation of the key
func (k *Point) String() string { func (k *Point) String() string {
k.init() k.init()
return output(k.KV, k.NS, "*", k.DB, "*", k.TB, "¤", k.IX, k.FD, k.ID) return output(k.KV, "*", k.NS, "*", k.DB, "*", k.TB, "¤", k.IX, k.FD, k.ID)
} }

View file

@ -40,18 +40,18 @@ func (k *SC) Copy() *SC {
// Encode encodes the key into binary // Encode encodes the key into binary
func (k *SC) Encode() []byte { func (k *SC) Encode() []byte {
k.init() k.init()
return encode(k.KV, k.NS, "*", k.DB, "!", "s", k.SC) return encode(k.KV, "*", k.NS, "*", k.DB, "!", "s", k.SC)
} }
// Decode decodes the key from binary // Decode decodes the key from binary
func (k *SC) Decode(data []byte) { func (k *SC) Decode(data []byte) {
k.init() k.init()
var __ string var __ string
decode(data, &k.KV, &k.NS, &__, &k.DB, &__, &__, &k.SC) decode(data, &k.KV, &__, &k.NS, &__, &k.DB, &__, &__, &k.SC)
} }
// String returns a string representation of the key // String returns a string representation of the key
func (k *SC) String() string { func (k *SC) String() string {
k.init() k.init()
return output(k.KV, k.NS, "*", k.DB, "!", "s", k.SC) return output(k.KV, "*", k.NS, "*", k.DB, "!", "s", k.SC)
} }

View file

@ -42,18 +42,18 @@ func (k *ST) Copy() *ST {
// Encode encodes the key into binary // Encode encodes the key into binary
func (k *ST) Encode() []byte { func (k *ST) Encode() []byte {
k.init() k.init()
return encode(k.KV, k.NS, "*", k.DB, "!", "s", k.SC, "!", "t", k.TK) return encode(k.KV, "*", k.NS, "*", k.DB, "!", "s", k.SC, "!", "k", k.TK)
} }
// Decode decodes the key from binary // Decode decodes the key from binary
func (k *ST) Decode(data []byte) { func (k *ST) Decode(data []byte) {
k.init() k.init()
var __ string var __ string
decode(data, &k.KV, &k.NS, &__, &k.DB, &__, &__, &k.SC, &__, &__, &k.TK) decode(data, &k.KV, &__, &k.NS, &__, &k.DB, &__, &__, &k.SC, &__, &__, &k.TK)
} }
// String returns a string representation of the key // String returns a string representation of the key
func (k *ST) String() string { func (k *ST) String() string {
k.init() k.init()
return output(k.KV, k.NS, "*", k.DB, "!", "s", k.SC, "!", "t", k.TK) return output(k.KV, "*", k.NS, "*", k.DB, "!", "s", k.SC, "!", "k", k.TK)
} }

View file

@ -40,18 +40,18 @@ func (k *Table) Copy() *Table {
// Encode encodes the key into binary // Encode encodes the key into binary
func (k *Table) Encode() []byte { func (k *Table) Encode() []byte {
k.init() k.init()
return encode(k.KV, k.NS, "*", k.DB, "*", k.TB, "*") return encode(k.KV, "*", k.NS, "*", k.DB, "*", k.TB)
} }
// Decode decodes the key from binary // Decode decodes the key from binary
func (k *Table) Decode(data []byte) { func (k *Table) Decode(data []byte) {
k.init() k.init()
var __ string var __ string
decode(data, &k.KV, &k.NS, &__, &k.DB, &__, &k.TB, __) decode(data, &k.KV, &__, &k.NS, &__, &k.DB, &__, &k.TB)
} }
// String returns a string representation of the key // String returns a string representation of the key
func (k *Table) String() string { func (k *Table) String() string {
k.init() k.init()
return output(k.KV, k.NS, "*", k.DB, "*", k.TB, "*") return output(k.KV, "*", k.NS, "*", k.DB, "*", k.TB)
} }

View file

@ -40,18 +40,18 @@ func (k *TB) Copy() *TB {
// Encode encodes the key into binary // Encode encodes the key into binary
func (k *TB) Encode() []byte { func (k *TB) Encode() []byte {
k.init() k.init()
return encode(k.KV, k.NS, "*", k.DB, "*", k.TB) return encode(k.KV, "*", k.NS, "*", k.DB, "!", "t", k.TB)
} }
// Decode decodes the key from binary // Decode decodes the key from binary
func (k *TB) Decode(data []byte) { func (k *TB) Decode(data []byte) {
k.init() k.init()
var __ string var __ string
decode(data, &k.KV, &k.NS, &__, &k.DB, &__, &k.TB) decode(data, &k.KV, &__, &k.NS, &__, &k.DB, &__, &__, &k.TB)
} }
// String returns a string representation of the key // String returns a string representation of the key
func (k *TB) String() string { func (k *TB) String() string {
k.init() k.init()
return output(k.KV, k.NS, "*", k.DB, "*", k.TB) return output(k.KV, "*", k.NS, "*", k.DB, "!", "t", k.TB)
} }

View file

@ -42,18 +42,18 @@ func (k *Thing) Copy() *Thing {
// Encode encodes the key into binary // Encode encodes the key into binary
func (k *Thing) Encode() []byte { func (k *Thing) Encode() []byte {
k.init() k.init()
return encode(k.KV, k.NS, "*", k.DB, "*", k.TB, "*", k.ID) return encode(k.KV, "*", k.NS, "*", k.DB, "*", k.TB, "*", k.ID)
} }
// Decode decodes the key from binary // Decode decodes the key from binary
func (k *Thing) Decode(data []byte) { func (k *Thing) Decode(data []byte) {
k.init() k.init()
var __ string var __ string
decode(data, &k.KV, &k.NS, &__, &k.DB, &__, &k.TB, &__, &k.ID) decode(data, &k.KV, &__, &k.NS, &__, &k.DB, &__, &k.TB, &__, &k.ID)
} }
// String returns a string representation of the key // String returns a string representation of the key
func (k *Thing) String() string { func (k *Thing) String() string {
k.init() k.init()
return output(k.KV, k.NS, "*", k.DB, "*", k.TB, "*", k.ID) return output(k.KV, "*", k.NS, "*", k.DB, "*", k.TB, "*", k.ID)
} }