From 84b72e25d2ba18e486cfd5f2b22e78f2955df1db Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Fri, 9 Feb 2018 15:08:27 +0000 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20use=20of=20ClrL,=20GetL,=20DelL?= =?UTF-8?q?,=20PutL=20methods=20on=20KV=20store?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- db/remove.go | 18 ++++- kvs/rixxdb/tx.go | 139 +++++++++--------------------------- kvs/tx.go | 6 -- mem/mem.go | 28 ++++---- util/keys/database.go | 55 +++++++++++++++ util/keys/db.go | 6 +- util/keys/dt.go | 6 +- util/keys/du.go | 6 +- util/keys/edge.go | 6 +- util/keys/ev.go | 6 +- util/keys/fd.go | 6 +- util/keys/field.go | 6 +- util/keys/ft.go | 6 +- util/keys/index.go | 6 +- util/keys/ix.go | 6 +- util/keys/keys_test.go | 157 ++++++++++++++++++++++++----------------- util/keys/lv.go | 6 +- util/keys/namespace.go | 53 ++++++++++++++ util/keys/ns.go | 7 +- util/keys/nt.go | 6 +- util/keys/nu.go | 6 +- util/keys/patch.go | 6 +- util/keys/point.go | 6 +- util/keys/sc.go | 6 +- util/keys/st.go | 6 +- util/keys/table.go | 6 +- util/keys/tb.go | 6 +- util/keys/thing.go | 6 +- 28 files changed, 327 insertions(+), 256 deletions(-) create mode 100644 util/keys/database.go create mode 100644 util/keys/namespace.go diff --git a/db/remove.go b/db/remove.go index 4ed988da..d362e43d 100644 --- a/db/remove.go +++ b/db/remove.go @@ -26,7 +26,10 @@ func (e *executor) executeRemoveNamespace(ctx context.Context, ast *sql.RemoveNa e.dbo.DelNS(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 @@ -37,7 +40,10 @@ func (e *executor) executeRemoveDatabase(ctx context.Context, ast *sql.RemoveDat e.dbo.DelDB(ast.NS, 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 @@ -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} - _, 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 { return nil, err } diff --git a/kvs/rixxdb/tx.go b/kvs/rixxdb/tx.go index c047d951..b44d2a85 100644 --- a/kvs/rixxdb/tx.go +++ b/kvs/rixxdb/tx.go @@ -23,7 +23,7 @@ type TX struct { 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 { case nil: @@ -34,11 +34,11 @@ func one(all kvs.KV, err error) (kvs.KV, error) { 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 { case nil: @@ -49,7 +49,13 @@ func many(all []kvs.KV, err error) ([]kvs.KV, error) { 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) { - all, err := tx.pntr.Clr(key) - return one(all, 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) + res, err := tx.pntr.Clr(key) + return one(res, err) } func (tx *TX) ClrP(key []byte, max uint64) ([]kvs.KV, error) { - all, err := tx.pntr.ClrP(key, max) - out := make([]kvs.KV, len(all)) - for i, v := range all { - out[i] = v - } - return many(out, err) + res, err := tx.pntr.ClrP(key, max) + return many(res, err) } func (tx *TX) ClrR(beg []byte, end []byte, max uint64) ([]kvs.KV, error) { - all, err := tx.pntr.ClrR(beg, end, max) - out := make([]kvs.KV, len(all)) - for i, v := range all { - out[i] = v - } - return many(out, err) + res, err := tx.pntr.ClrR(beg, end, max) + return many(res, err) } func (tx *TX) Get(ver int64, key []byte) (kvs.KV, error) { - all, err := tx.pntr.Get(uint64(ver), key) - return one(all, 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) + res, err := tx.pntr.Get(uint64(ver), key) + return one(res, err) } func (tx *TX) GetP(ver int64, key []byte, max uint64) ([]kvs.KV, error) { - all, err := tx.pntr.GetP(uint64(ver), key, max) - out := make([]kvs.KV, len(all)) - for i, v := range all { - out[i] = v - } - return many(out, err) + res, err := tx.pntr.GetP(uint64(ver), key, max) + return many(res, err) } 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) - out := make([]kvs.KV, len(all)) - for i, v := range all { - out[i] = v - } - return many(out, err) + res, err := tx.pntr.GetR(uint64(ver), beg, end, max) + return many(res, err) } func (tx *TX) Del(ver int64, key []byte) (kvs.KV, error) { - all, err := tx.pntr.Del(uint64(ver), key) - return one(all, err) + res, err := tx.pntr.Del(uint64(ver), key) + return one(res, err) } func (tx *TX) DelC(ver int64, key []byte, exp []byte) (kvs.KV, error) { - return tx.pntr.DelC(uint64(ver), key, exp) -} - -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) + res, err := tx.pntr.DelC(uint64(ver), key, exp) + return one(res, err) } func (tx *TX) DelP(ver int64, key []byte, max uint64) ([]kvs.KV, error) { - all, err := tx.pntr.DelP(uint64(ver), key, max) - out := make([]kvs.KV, len(all)) - for i, v := range all { - out[i] = v - } - return many(out, err) + res, err := tx.pntr.DelP(uint64(ver), key, max) + return many(res, err) } 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) - out := make([]kvs.KV, len(all)) - for i, v := range all { - out[i] = v - } - return many(out, err) + res, err := tx.pntr.DelR(uint64(ver), beg, end, max) + return many(res, err) } func (tx *TX) Put(ver int64, key []byte, val []byte) (kvs.KV, error) { - all, err := tx.pntr.Put(uint64(ver), key, val) - return one(all, err) + res, err := tx.pntr.Put(uint64(ver), key, val) + return one(res, err) } 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) - return one(all, 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) + res, err := tx.pntr.PutC(uint64(ver), key, val, exp) + return one(res, err) } diff --git a/kvs/tx.go b/kvs/tx.go index a839b284..7e543df7 100644 --- a/kvs/tx.go +++ b/kvs/tx.go @@ -21,24 +21,18 @@ type TX interface { Commit() error Clr([]byte) (KV, error) - ClrL([]byte, uint64) ([]KV, error) ClrP([]byte, uint64) ([]KV, error) ClrR([]byte, []byte, uint64) ([]KV, error) Get(int64, []byte) (KV, error) - GetL(int64, []byte, uint64) ([]KV, error) GetP(int64, []byte, uint64) ([]KV, error) GetR(int64, []byte, []byte, uint64) ([]KV, error) Del(int64, []byte) (KV, error) DelC(int64, []byte, []byte) (KV, error) - DelL(int64, []byte, uint64) ([]KV, error) DelP(int64, []byte, uint64) ([]KV, error) DelR(int64, []byte, []byte, uint64) ([]KV, error) Put(int64, []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) } diff --git a/mem/mem.go b/mem/mem.go index 9137ce45..a5a91b2d 100644 --- a/mem/mem.go +++ b/mem/mem.go @@ -78,7 +78,7 @@ func (c *Cache) AllNS() (out []*sql.DefineNamespaceStatement, err error) { var kvs []kvs.KV 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 } @@ -163,7 +163,7 @@ func (c *Cache) AllNT(ns string) (out []*sql.DefineTokenStatement, err error) { var kvs []kvs.KV 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 } @@ -204,7 +204,7 @@ func (c *Cache) AllNU(ns string) (out []*sql.DefineLoginStatement, err error) { var kvs []kvs.KV 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 } @@ -251,7 +251,7 @@ func (c *Cache) AllDB(ns string) (out []*sql.DefineDatabaseStatement, err error) var kvs []kvs.KV 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 } @@ -340,7 +340,7 @@ func (c *Cache) AllDT(ns, db string) (out []*sql.DefineTokenStatement, err error var kvs []kvs.KV 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 } @@ -381,7 +381,7 @@ func (c *Cache) AllDU(ns, db string) (out []*sql.DefineLoginStatement, err error var kvs []kvs.KV 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 } @@ -422,7 +422,7 @@ func (c *Cache) AllSC(ns, db string) (out []*sql.DefineScopeStatement, err error var kvs []kvs.KV 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 } @@ -463,7 +463,7 @@ func (c *Cache) AllST(ns, db, sc string) (out []*sql.DefineTokenStatement, err e var kvs []kvs.KV 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 } @@ -510,7 +510,7 @@ func (c *Cache) AllTB(ns, db string) (out []*sql.DefineTableStatement, err error var kvs []kvs.KV 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 } @@ -607,7 +607,7 @@ func (c *Cache) AllEV(ns, db, tb string) (out []*sql.DefineEventStatement, err e var kvs []kvs.KV 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 } @@ -674,7 +674,7 @@ func (c *Cache) AllFD(ns, db, tb string) (out []*sql.DefineFieldStatement, err e var kvs []kvs.KV 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 } @@ -741,7 +741,7 @@ func (c *Cache) AllIX(ns, db, tb string) (out []*sql.DefineIndexStatement, err e var kvs []kvs.KV 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 } @@ -808,7 +808,7 @@ func (c *Cache) AllFT(ns, db, tb string) (out []*sql.DefineTableStatement, err e var kvs []kvs.KV 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 } @@ -875,7 +875,7 @@ func (c *Cache) AllLV(ns, db, tb string) (out []*sql.LiveStatement, err error) { var kvs []kvs.KV 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 } diff --git a/util/keys/database.go b/util/keys/database.go new file mode 100644 index 00000000..0fddbaee --- /dev/null +++ b/util/keys/database.go @@ -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) +} diff --git a/util/keys/db.go b/util/keys/db.go index 501d6399..b21f01af 100644 --- a/util/keys/db.go +++ b/util/keys/db.go @@ -38,18 +38,18 @@ func (k *DB) Copy() *DB { // Encode encodes the key into binary func (k *DB) Encode() []byte { 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 func (k *DB) Decode(data []byte) { k.init() 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 func (k *DB) String() string { k.init() - return output(k.KV, k.NS, "*", k.DB) + return output(k.KV, "*", k.NS, "!", "d", k.DB) } diff --git a/util/keys/dt.go b/util/keys/dt.go index d4cd5a7b..ecbdeed4 100644 --- a/util/keys/dt.go +++ b/util/keys/dt.go @@ -40,18 +40,18 @@ func (k *DT) Copy() *DT { // Encode encodes the key into binary func (k *DT) Encode() []byte { 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 func (k *DT) Decode(data []byte) { k.init() 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 func (k *DT) String() string { k.init() - return output(k.KV, k.NS, "*", k.DB, "!", "t", k.TK) + return output(k.KV, "*", k.NS, "*", k.DB, "!", "k", k.TK) } diff --git a/util/keys/du.go b/util/keys/du.go index fdeb9eb6..708cea4d 100644 --- a/util/keys/du.go +++ b/util/keys/du.go @@ -40,18 +40,18 @@ func (k *DU) Copy() *DU { // Encode encodes the key into binary func (k *DU) Encode() []byte { 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 func (k *DU) Decode(data []byte) { k.init() 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 func (k *DU) String() string { k.init() - return output(k.KV, k.NS, "*", k.DB, "!", "u", k.US) + return output(k.KV, "*", k.NS, "*", k.DB, "!", "u", k.US) } diff --git a/util/keys/edge.go b/util/keys/edge.go index 5192447e..c0d0d991 100644 --- a/util/keys/edge.go +++ b/util/keys/edge.go @@ -57,18 +57,18 @@ func (k *Edge) Copy() *Edge { // Encode encodes the key into binary func (k *Edge) Encode() []byte { 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 func (k *Edge) Decode(data []byte) { k.init() 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 func (k *Edge) String() string { 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) } diff --git a/util/keys/ev.go b/util/keys/ev.go index d077b484..7625344e 100644 --- a/util/keys/ev.go +++ b/util/keys/ev.go @@ -42,18 +42,18 @@ func (k *EV) Copy() *EV { // Encode encodes the key into binary func (k *EV) Encode() []byte { 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 func (k *EV) Decode(data []byte) { k.init() 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 func (k *EV) String() string { 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) } diff --git a/util/keys/fd.go b/util/keys/fd.go index d0068ddc..63d0b9cf 100644 --- a/util/keys/fd.go +++ b/util/keys/fd.go @@ -42,18 +42,18 @@ func (k *FD) Copy() *FD { // Encode encodes the key into binary func (k *FD) Encode() []byte { 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 func (k *FD) Decode(data []byte) { k.init() 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 func (k *FD) String() string { 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) } diff --git a/util/keys/field.go b/util/keys/field.go index 4c54d348..b90b403c 100644 --- a/util/keys/field.go +++ b/util/keys/field.go @@ -44,18 +44,18 @@ func (k *Field) Copy() *Field { // Encode encodes the key into binary func (k *Field) Encode() []byte { 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 func (k *Field) Decode(data []byte) { k.init() 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 func (k *Field) String() string { 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) } diff --git a/util/keys/ft.go b/util/keys/ft.go index 3de02d33..6c600b5b 100644 --- a/util/keys/ft.go +++ b/util/keys/ft.go @@ -41,18 +41,18 @@ func (k *FT) Copy() *FT { // Encode encodes the key into binary func (k *FT) Encode() []byte { 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 func (k *FT) Decode(data []byte) { k.init() 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 func (k *FT) String() string { 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) } diff --git a/util/keys/index.go b/util/keys/index.go index d6fe15ee..39b3fd79 100644 --- a/util/keys/index.go +++ b/util/keys/index.go @@ -44,18 +44,18 @@ func (k *Index) Copy() *Index { // Encode encodes the key into binary func (k *Index) Encode() []byte { 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 func (k *Index) Decode(data []byte) { k.init() 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 func (k *Index) String() string { 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) } diff --git a/util/keys/ix.go b/util/keys/ix.go index f2b25850..95d293d3 100644 --- a/util/keys/ix.go +++ b/util/keys/ix.go @@ -42,18 +42,18 @@ func (k *IX) Copy() *IX { // Encode encodes the key into binary func (k *IX) Encode() []byte { 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 func (k *IX) Decode(data []byte) { k.init() 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 func (k *IX) String() string { 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) } diff --git a/util/keys/keys_test.go b/util/keys/keys_test.go index 771dba6e..6a8d8ccf 100644 --- a/util/keys/keys_test.go +++ b/util/keys/keys_test.go @@ -86,152 +86,162 @@ func TestMain(t *testing.T) { new: &KV{}, }, { - str: "/surreal/abcum", + str: "/surreal/!/n/abcum", obj: &NS{KV: "surreal", NS: "abcum"}, new: &NS{}, }, { - str: "/surreal/abcum/!/t/default", - obj: &NT{KV: "surreal", NS: "abcum", TK: "default"}, - new: &NT{}, + str: "/surreal/*/abcum", + obj: &Namespace{KV: "surreal", NS: "abcum"}, + new: &Namespace{}, }, { - str: "/surreal/abcum/!/u/info@abcum.com", - obj: &NU{KV: "surreal", NS: "abcum", US: "info@abcum.com"}, - new: &NU{}, - }, - { - str: "/surreal/abcum/*/database", + str: "/surreal/*/abcum/!/d/database", obj: &DB{KV: "surreal", NS: "abcum", DB: "database"}, new: &DB{}, }, { - str: "/surreal/abcum/*/database/!/s/admin", - obj: &SC{KV: "surreal", NS: "abcum", DB: "database", SC: "admin"}, - new: &SC{}, + str: "/surreal/*/abcum/!/k/default", + obj: &NT{KV: "surreal", NS: "abcum", TK: "default"}, + new: &NT{}, }, { - str: "/surreal/abcum/*/database/!/s/admin/!/t/default", - obj: &ST{KV: "surreal", NS: "abcum", DB: "database", SC: "admin", TK: "default"}, - new: &ST{}, + str: "/surreal/*/abcum/!/u/info@abcum.com", + obj: &NU{KV: "surreal", NS: "abcum", US: "info@abcum.com"}, + 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"}, new: &DT{}, }, { - str: "/surreal/abcum/*/database/!/u/info@abcum.com", - obj: &DU{KV: "surreal", NS: "abcum", DB: "database", US: "info@abcum.com"}, - new: &DU{}, + str: "/surreal/*/abcum/*/database/!/s/admin", + obj: &SC{KV: "surreal", NS: "abcum", DB: "database", SC: "admin"}, + 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"}, new: &TB{}, }, { - 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/!/u/info@abcum.com", + obj: &DU{KV: "surreal", NS: "abcum", DB: "database", US: "info@abcum.com"}, + new: &DU{}, }, { - 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/*", + str: "/surreal/*/abcum/*/database/*/person", obj: &Table{KV: "surreal", NS: "abcum", DB: "database", TB: "person"}, 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}, 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"}, 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"}, 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"}, 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"}, 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"}, 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"}, 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}, 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}, 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}, new: &Patch{}, }, { - str: "/surreal/abcum/*/database/*/person/¤/names/[false account:1 lastname firstname]", + str: "/surreal/*/abcum/*/database/*/person/¤/names/[false account:1 lastname firstname]", obj: &Index{KV: "surreal", NS: "abcum", DB: "database", TB: "person", IX: "names", FD: []interface{}{false, "account:1", "lastname", nil, "firstname"}}, 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"}}, 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"}, new: &Point{}, }, { - str: "/surreal/abcum/*/database/*/person/¤/uniqs/[false account:1 lastname firstname]/873c2f37-ea03-4c5e-843e-cf393af44155", + str: "/surreal/*/abcum/*/database/*/person/¤/uniqs/[false account:1 lastname 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"}, 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"}, new: &Point{}, }, @@ -368,8 +378,26 @@ func TestMain(t *testing.T) { nos []Key }{ { - obj: &TB{KV: "kv", NS: "ns", DB: "db", TB: "person"}, + obj: &Namespace{KV: "kv", NS: "ns"}, 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: "test"}, &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"}}, }, 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: "other", 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: "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: "ns", DB: "db", TB: "other", 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: "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"}}, }, }, { diff --git a/util/keys/lv.go b/util/keys/lv.go index 0b5ff32e..cfe73413 100644 --- a/util/keys/lv.go +++ b/util/keys/lv.go @@ -42,18 +42,18 @@ func (k *LV) Copy() *LV { // Encode encodes the key into binary func (k *LV) Encode() []byte { 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 func (k *LV) Decode(data []byte) { k.init() 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 func (k *LV) String() string { 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) } diff --git a/util/keys/namespace.go b/util/keys/namespace.go new file mode 100644 index 00000000..fbb5bf7d --- /dev/null +++ b/util/keys/namespace.go @@ -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) +} diff --git a/util/keys/ns.go b/util/keys/ns.go index 7a5f0be4..36b7ce79 100644 --- a/util/keys/ns.go +++ b/util/keys/ns.go @@ -36,17 +36,18 @@ func (k *NS) Copy() *NS { // Encode encodes the key into binary func (k *NS) Encode() []byte { k.init() - return encode(k.KV, k.NS) + return encode(k.KV, "!", "n", k.NS) } // Decode decodes the key from binary func (k *NS) Decode(data []byte) { k.init() - decode(data, &k.KV, &k.NS) + var __ string + decode(data, &k.KV, &__, &__, &k.NS) } // String returns a string representation of the key func (k *NS) String() string { k.init() - return output(k.KV, k.NS) + return output(k.KV, "!", "n", k.NS) } diff --git a/util/keys/nt.go b/util/keys/nt.go index 5acdc0ca..807420ed 100644 --- a/util/keys/nt.go +++ b/util/keys/nt.go @@ -38,18 +38,18 @@ func (k *NT) Copy() *NT { // Encode encodes the key into binary func (k *NT) Encode() []byte { 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 func (k *NT) Decode(data []byte) { k.init() 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 func (k *NT) String() string { k.init() - return output(k.KV, k.NS, "!", "t", k.TK) + return output(k.KV, "*", k.NS, "!", "k", k.TK) } diff --git a/util/keys/nu.go b/util/keys/nu.go index 9b2bd7f9..e2209f4b 100644 --- a/util/keys/nu.go +++ b/util/keys/nu.go @@ -38,18 +38,18 @@ func (k *NU) Copy() *NU { // Encode encodes the key into binary func (k *NU) Encode() []byte { 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 func (k *NU) Decode(data []byte) { k.init() 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 func (k *NU) String() string { k.init() - return output(k.KV, k.NS, "!", "u", k.US) + return output(k.KV, "*", k.NS, "!", "u", k.US) } diff --git a/util/keys/patch.go b/util/keys/patch.go index 505f29bc..9e61e4ff 100644 --- a/util/keys/patch.go +++ b/util/keys/patch.go @@ -51,18 +51,18 @@ func (k *Patch) Copy() *Patch { // Encode encodes the key into binary func (k *Patch) Encode() []byte { 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 func (k *Patch) Decode(data []byte) { k.init() 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 func (k *Patch) String() string { 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)) } diff --git a/util/keys/point.go b/util/keys/point.go index 1f0cb581..97e1d35e 100644 --- a/util/keys/point.go +++ b/util/keys/point.go @@ -46,18 +46,18 @@ func (k *Point) Copy() *Point { // Encode encodes the key into binary func (k *Point) Encode() []byte { 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 func (k *Point) Decode(data []byte) { k.init() 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 func (k *Point) String() string { 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) } diff --git a/util/keys/sc.go b/util/keys/sc.go index 6ffc060d..43084ba8 100644 --- a/util/keys/sc.go +++ b/util/keys/sc.go @@ -40,18 +40,18 @@ func (k *SC) Copy() *SC { // Encode encodes the key into binary func (k *SC) Encode() []byte { 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 func (k *SC) Decode(data []byte) { k.init() 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 func (k *SC) String() string { k.init() - return output(k.KV, k.NS, "*", k.DB, "!", "s", k.SC) + return output(k.KV, "*", k.NS, "*", k.DB, "!", "s", k.SC) } diff --git a/util/keys/st.go b/util/keys/st.go index 0cd294a9..7ffe5ddb 100644 --- a/util/keys/st.go +++ b/util/keys/st.go @@ -42,18 +42,18 @@ func (k *ST) Copy() *ST { // Encode encodes the key into binary func (k *ST) Encode() []byte { 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 func (k *ST) Decode(data []byte) { k.init() 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 func (k *ST) String() string { 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) } diff --git a/util/keys/table.go b/util/keys/table.go index 9852547d..5bfe0ba5 100644 --- a/util/keys/table.go +++ b/util/keys/table.go @@ -40,18 +40,18 @@ func (k *Table) Copy() *Table { // Encode encodes the key into binary func (k *Table) Encode() []byte { 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 func (k *Table) Decode(data []byte) { k.init() 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 func (k *Table) String() string { k.init() - return output(k.KV, k.NS, "*", k.DB, "*", k.TB, "*") + return output(k.KV, "*", k.NS, "*", k.DB, "*", k.TB) } diff --git a/util/keys/tb.go b/util/keys/tb.go index 32ad95e0..de178fe1 100644 --- a/util/keys/tb.go +++ b/util/keys/tb.go @@ -40,18 +40,18 @@ func (k *TB) Copy() *TB { // Encode encodes the key into binary func (k *TB) Encode() []byte { 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 func (k *TB) Decode(data []byte) { k.init() 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 func (k *TB) String() string { k.init() - return output(k.KV, k.NS, "*", k.DB, "*", k.TB) + return output(k.KV, "*", k.NS, "*", k.DB, "!", "t", k.TB) } diff --git a/util/keys/thing.go b/util/keys/thing.go index 73a669b3..7fae93ac 100644 --- a/util/keys/thing.go +++ b/util/keys/thing.go @@ -42,18 +42,18 @@ func (k *Thing) Copy() *Thing { // Encode encodes the key into binary func (k *Thing) Encode() []byte { 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 func (k *Thing) Decode(data []byte) { k.init() 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 func (k *Thing) String() string { 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) }