Update keys package
This commit is contained in:
parent
99ea0a3368
commit
f56196a150
26 changed files with 481 additions and 259 deletions
|
@ -14,40 +14,32 @@
|
|||
|
||||
package keys
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// DB ...
|
||||
type DB struct {
|
||||
KV interface{}
|
||||
CF interface{}
|
||||
TK interface{}
|
||||
NS interface{}
|
||||
DB interface{}
|
||||
}
|
||||
|
||||
// init initialises the key
|
||||
func (k *DB) init() *DB {
|
||||
k.CF = "!"
|
||||
k.TK = "d"
|
||||
return k
|
||||
}
|
||||
|
||||
// Encode encodes the key into binary
|
||||
func (k *DB) Encode() []byte {
|
||||
k.init()
|
||||
return encode(k.KV, k.CF, k.TK, k.NS, k.DB)
|
||||
return encode(k.KV, k.NS, "*", k.DB)
|
||||
}
|
||||
|
||||
// Decode decodes the key from binary
|
||||
func (k *DB) Decode(data []byte) {
|
||||
k.init()
|
||||
decode(data, &k.KV, &k.CF, &k.TK, &k.NS, &k.DB)
|
||||
decode(data, &k.KV, &k.NS, &skip, &k.DB)
|
||||
}
|
||||
|
||||
// String returns a string representation of the key
|
||||
func (k *DB) String() string {
|
||||
k.init()
|
||||
return fmt.Sprintf("/%s/%s/%s/%s/%s", k.KV, k.CF, k.TK, k.NS, k.DB)
|
||||
return output(k.KV, k.NS, "*", k.DB)
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ type decoder struct {
|
|||
r *reader
|
||||
}
|
||||
|
||||
// Decode decodes an encoded string using the unicode collation algorithm.
|
||||
// decode decodes an encoded string using the unicode collation algorithm.
|
||||
func decode(data []byte, items ...interface{}) {
|
||||
newDecoder(bytes.NewReader(data)).Decode(items...)
|
||||
}
|
|
@ -14,42 +14,33 @@
|
|||
|
||||
package keys
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// RU ...
|
||||
type RU struct {
|
||||
// DT ...
|
||||
type DT struct {
|
||||
KV interface{}
|
||||
CF interface{}
|
||||
TK interface{}
|
||||
NS interface{}
|
||||
DB interface{}
|
||||
TB interface{}
|
||||
RU interface{}
|
||||
TK interface{}
|
||||
}
|
||||
|
||||
// init initialises the key
|
||||
func (k *RU) init() *RU {
|
||||
k.CF = "!"
|
||||
k.TK = "r"
|
||||
func (k *DT) init() *DT {
|
||||
return k
|
||||
}
|
||||
|
||||
// Encode encodes the key into binary
|
||||
func (k *RU) Encode() []byte {
|
||||
func (k *DT) Encode() []byte {
|
||||
k.init()
|
||||
return encode(k.KV, k.CF, k.TK, k.NS, k.DB, k.TB, k.RU)
|
||||
return encode(k.KV, k.NS, "*", k.DB, "!", "t", k.TK)
|
||||
}
|
||||
|
||||
// Decode decodes the key from binary
|
||||
func (k *RU) Decode(data []byte) {
|
||||
func (k *DT) Decode(data []byte) {
|
||||
k.init()
|
||||
decode(data, &k.KV, &k.CF, &k.TK, &k.NS, &k.DB, &k.TB, &k.RU)
|
||||
decode(data, &k.KV, &k.NS, &skip, &k.DB, &skip, &skip, &k.TK)
|
||||
}
|
||||
|
||||
// String returns a string representation of the key
|
||||
func (k *RU) String() string {
|
||||
func (k *DT) String() string {
|
||||
k.init()
|
||||
return fmt.Sprintf("/%s/%s/%s/%s/%s/%s/%s", k.KV, k.CF, k.TK, k.NS, k.DB, k.TB, k.RU)
|
||||
return output(k.KV, k.NS, "*", k.DB, "!", "t", k.TK)
|
||||
}
|
46
util/keys/du.go
Normal file
46
util/keys/du.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
// 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
|
||||
|
||||
// DU ...
|
||||
type DU struct {
|
||||
KV interface{}
|
||||
NS interface{}
|
||||
DB interface{}
|
||||
US interface{}
|
||||
}
|
||||
|
||||
// init initialises the key
|
||||
func (k *DU) init() *DU {
|
||||
return k
|
||||
}
|
||||
|
||||
// Encode encodes the key into binary
|
||||
func (k *DU) Encode() []byte {
|
||||
k.init()
|
||||
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()
|
||||
decode(data, &k.KV, &k.NS, &skip, &k.DB, &skip, &skip, &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)
|
||||
}
|
|
@ -14,25 +14,26 @@
|
|||
|
||||
package keys
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Edge ...
|
||||
type Edge struct {
|
||||
KV interface{}
|
||||
NS interface{}
|
||||
DB interface{}
|
||||
TB interface{}
|
||||
TK interface{}
|
||||
ID interface{}
|
||||
TK interface{}
|
||||
TP interface{}
|
||||
FT interface{}
|
||||
FK interface{}
|
||||
}
|
||||
|
||||
// init initialises the key
|
||||
func (k *Edge) init() *Edge {
|
||||
if k.TK == nil {
|
||||
switch k.TK {
|
||||
case "«»":
|
||||
case "‹", "›":
|
||||
case "«", "»":
|
||||
default:
|
||||
k.TK = "«»"
|
||||
}
|
||||
return k
|
||||
|
@ -41,17 +42,17 @@ func (k *Edge) init() *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.TK, k.ID, k.TP, 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()
|
||||
decode(data, &k.KV, &k.NS, &k.DB, &k.TB, &k.TK, &k.ID, &k.TP, &k.FK)
|
||||
decode(data, &k.KV, &k.NS, &skip, &k.DB, &skip, &k.TB, &skip, &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 fmt.Sprintf("/%s/%s/%s/%s/%s/%s/%s/%s", k.KV, k.NS, k.DB, k.TB, k.TK, k.ID, k.TP, k.FK)
|
||||
return output(k.KV, k.NS, "*", k.DB, "*", k.TB, "*", k.ID, k.TK, k.TP, k.FT, k.FK)
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ type encoder struct {
|
|||
w *writer
|
||||
}
|
||||
|
||||
// Encode encodes an interface using the unicode collation algorithm.
|
||||
// encode encodes an interface using the unicode collation algorithm.
|
||||
func encode(items ...interface{}) []byte {
|
||||
b := &bytes.Buffer{}
|
||||
newEncoder(b).Encode(items...)
|
|
@ -14,15 +14,9 @@
|
|||
|
||||
package keys
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// FD ...
|
||||
type FD struct {
|
||||
KV interface{}
|
||||
CF interface{}
|
||||
TK interface{}
|
||||
NS interface{}
|
||||
DB interface{}
|
||||
TB interface{}
|
||||
|
@ -31,25 +25,23 @@ type FD struct {
|
|||
|
||||
// init initialises the key
|
||||
func (k *FD) init() *FD {
|
||||
k.CF = "!"
|
||||
k.TK = "f"
|
||||
return k
|
||||
}
|
||||
|
||||
// Encode encodes the key into binary
|
||||
func (k *FD) Encode() []byte {
|
||||
k.init()
|
||||
return encode(k.KV, k.CF, k.TK, k.NS, k.DB, k.TB, 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()
|
||||
decode(data, &k.KV, &k.CF, &k.TK, &k.NS, &k.DB, &k.TB, &k.FD)
|
||||
decode(data, &k.KV, &k.NS, &skip, &k.DB, &skip, &k.TB, &skip, &skip, &k.FD)
|
||||
}
|
||||
|
||||
// String returns a string representation of the key
|
||||
func (k *FD) String() string {
|
||||
k.init()
|
||||
return fmt.Sprintf("/%s/%s/%s/%s/%s/%s/%s", k.KV, k.CF, k.TK, k.NS, k.DB, k.TB, k.FD)
|
||||
return output(k.KV, k.NS, "*", k.DB, "*", k.TB, "!", "f", k.FD)
|
||||
}
|
||||
|
|
|
@ -14,46 +14,35 @@
|
|||
|
||||
package keys
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Event ...
|
||||
type Event struct {
|
||||
// Field ...
|
||||
type Field struct {
|
||||
KV interface{}
|
||||
NS interface{}
|
||||
DB interface{}
|
||||
TB interface{}
|
||||
TK interface{}
|
||||
ID interface{}
|
||||
TP interface{}
|
||||
AT time.Time
|
||||
FD interface{}
|
||||
}
|
||||
|
||||
// init initialises the key
|
||||
func (k *Event) init() *Event {
|
||||
k.TK = "•"
|
||||
if k.AT.IsZero() {
|
||||
k.AT = time.Now()
|
||||
}
|
||||
func (k *Field) init() *Field {
|
||||
return k
|
||||
}
|
||||
|
||||
// Encode encodes the key into binary
|
||||
func (k *Event) Encode() []byte {
|
||||
func (k *Field) Encode() []byte {
|
||||
k.init()
|
||||
return encode(k.KV, k.NS, k.DB, k.TB, k.TK, k.ID, k.TP, k.AT)
|
||||
return encode(k.KV, k.NS, "*", k.DB, "*", k.TB, "*", k.ID, "*", k.FD)
|
||||
}
|
||||
|
||||
// Decode decodes the key from binary
|
||||
func (k *Event) Decode(data []byte) {
|
||||
func (k *Field) Decode(data []byte) {
|
||||
k.init()
|
||||
decode(data, &k.KV, &k.NS, &k.DB, &k.TB, &k.TK, &k.ID, &k.TP, &k.AT)
|
||||
decode(data, &k.KV, &k.NS, &skip, &k.DB, &skip, &k.TB, &skip, &k.ID, &skip, &k.FD)
|
||||
}
|
||||
|
||||
// String returns a string representation of the key
|
||||
func (k *Event) String() string {
|
||||
func (k *Field) String() string {
|
||||
k.init()
|
||||
return fmt.Sprintf("/%s/%s/%s/%s/%s/%s/%s/%s", k.KV, k.NS, k.DB, k.TB, k.TK, k.ID, k.TP, k.AT.Format(time.RFC3339Nano))
|
||||
return output(k.KV, k.NS, "*", k.DB, "*", k.TB, "*", k.ID, "*", k.FD)
|
||||
}
|
|
@ -14,41 +14,35 @@
|
|||
|
||||
package keys
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Index ...
|
||||
type Index struct {
|
||||
KV interface{}
|
||||
NS interface{}
|
||||
DB interface{}
|
||||
TB interface{}
|
||||
TK interface{}
|
||||
IX interface{}
|
||||
FD interface{}
|
||||
}
|
||||
|
||||
// init initialises the key
|
||||
func (k *Index) init() *Index {
|
||||
k.TK = "∆"
|
||||
return k
|
||||
}
|
||||
|
||||
// Encode encodes the key into binary
|
||||
func (k *Index) Encode() []byte {
|
||||
k.init()
|
||||
return encode(k.KV, k.NS, k.DB, k.TB, k.TK, 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()
|
||||
decode(data, &k.KV, &k.NS, &k.DB, &k.TB, &k.TK, &k.IX, &k.FD)
|
||||
decode(data, &k.KV, &k.NS, &skip, &k.DB, &skip, &k.TB, &skip, &k.IX, &k.FD)
|
||||
}
|
||||
|
||||
// String returns a string representation of the key
|
||||
func (k *Index) String() string {
|
||||
k.init()
|
||||
return fmt.Sprintf("/%s/%s/%s/%s/%s/%s/%v", k.KV, k.NS, k.DB, k.TB, k.TK, k.IX, k.FD)
|
||||
return output(k.KV, k.NS, "*", k.DB, "*", k.TB, "¤", k.IX, k.FD)
|
||||
}
|
||||
|
|
|
@ -14,15 +14,9 @@
|
|||
|
||||
package keys
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// IX ...
|
||||
type IX struct {
|
||||
KV interface{}
|
||||
CF interface{}
|
||||
TK interface{}
|
||||
NS interface{}
|
||||
DB interface{}
|
||||
TB interface{}
|
||||
|
@ -31,25 +25,23 @@ type IX struct {
|
|||
|
||||
// init initialises the key
|
||||
func (k *IX) init() *IX {
|
||||
k.CF = "!"
|
||||
k.TK = "i"
|
||||
return k
|
||||
}
|
||||
|
||||
// Encode encodes the key into binary
|
||||
func (k *IX) Encode() []byte {
|
||||
k.init()
|
||||
return encode(k.KV, k.CF, k.TK, k.NS, k.DB, k.TB, 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()
|
||||
decode(data, &k.KV, &k.CF, &k.TK, &k.NS, &k.DB, &k.TB, &k.IX)
|
||||
decode(data, &k.KV, &k.NS, &skip, &k.DB, &skip, &k.TB, &skip, &skip, &k.IX)
|
||||
}
|
||||
|
||||
// String returns a string representation of the key
|
||||
func (k *IX) String() string {
|
||||
k.init()
|
||||
return fmt.Sprintf("/%s/%s/%s/%s/%s/%s/%s", k.KV, k.CF, k.TK, k.NS, k.DB, k.TB, k.IX)
|
||||
return output(k.KV, k.NS, "*", k.DB, "*", k.TB, "!", "i", k.IX)
|
||||
}
|
||||
|
|
|
@ -38,6 +38,10 @@ var (
|
|||
EndOfTime = time.Now().AddDate(50, 0, 0)
|
||||
)
|
||||
|
||||
var (
|
||||
skip interface{}
|
||||
)
|
||||
|
||||
var (
|
||||
cEND = byte(0x00)
|
||||
cPRE = byte(0x01)
|
||||
|
|
|
@ -54,6 +54,22 @@ func ShouldNotPrefix(actual interface{}, expected ...interface{}) string {
|
|||
}
|
||||
}
|
||||
|
||||
func ShouldSortBefore(actual interface{}, expected ...interface{}) string {
|
||||
if bytes.Compare(actual.([]byte), expected[0].([]byte)) > 0 {
|
||||
return fmt.Sprintf("%v should sort before \n%v\n%s\n%s", actual, expected[0], actual, expected[0])
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func ShouldSortAfter(actual interface{}, expected ...interface{}) string {
|
||||
if bytes.Compare(actual.([]byte), expected[0].([]byte)) < 0 {
|
||||
return fmt.Sprintf("%v should sort after \n%v\n%s\n%s", actual, expected[0], actual, expected[0])
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func TestMain(t *testing.T) {
|
||||
|
||||
clock, _ := time.Parse(time.RFC3339, "1987-06-22T08:00:00.123456789Z")
|
||||
|
@ -63,116 +79,161 @@ func TestMain(t *testing.T) {
|
|||
obj Key
|
||||
new Key
|
||||
}{
|
||||
{
|
||||
str: "/surreal",
|
||||
obj: &KV{KV: "surreal"},
|
||||
new: &KV{},
|
||||
},
|
||||
{
|
||||
str: "/surreal/!/¥",
|
||||
obj: &CK{KV: "surreal"},
|
||||
new: &CK{},
|
||||
},
|
||||
{
|
||||
str: "/surreal/!/n/abcum",
|
||||
str: "/surreal/abcum",
|
||||
obj: &NS{KV: "surreal", NS: "abcum"},
|
||||
new: &NS{},
|
||||
},
|
||||
{
|
||||
str: "/surreal/!/d/abcum/database",
|
||||
str: "/surreal/abcum/!/t/default",
|
||||
obj: &NT{KV: "surreal", NS: "abcum", TK: "default"},
|
||||
new: &NT{},
|
||||
},
|
||||
{
|
||||
str: "/surreal/abcum/!/u/info@abcum.com",
|
||||
obj: &NU{KV: "surreal", NS: "abcum", US: "info@abcum.com"},
|
||||
new: &NU{},
|
||||
},
|
||||
{
|
||||
str: "/surreal/abcum/*/database",
|
||||
obj: &DB{KV: "surreal", NS: "abcum", DB: "database"},
|
||||
new: &DB{},
|
||||
},
|
||||
{
|
||||
str: "/surreal/!/t/abcum/database/person",
|
||||
str: "/surreal/abcum/*/database/!/l/df8c74fa-428a-42b7-b279-b5fbe33d72a7",
|
||||
obj: &LV{KV: "surreal", NS: "abcum", DB: "database", LV: "df8c74fa-428a-42b7-b279-b5fbe33d72a7"},
|
||||
new: &LV{},
|
||||
},
|
||||
{
|
||||
str: "/surreal/abcum/*/database/!/s/admin",
|
||||
obj: &SC{KV: "surreal", NS: "abcum", DB: "database", SC: "admin"},
|
||||
new: &SC{},
|
||||
},
|
||||
{
|
||||
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/*/database/!/t/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/!/v/ages",
|
||||
obj: &VW{KV: "surreal", NS: "abcum", DB: "database", VW: "ages"},
|
||||
new: &VW{},
|
||||
},
|
||||
{
|
||||
str: "/surreal/abcum/*/database/*/person",
|
||||
obj: &TB{KV: "surreal", NS: "abcum", DB: "database", TB: "person"},
|
||||
new: &TB{},
|
||||
},
|
||||
{
|
||||
str: "/surreal/!/f/abcum/database/person/fullname",
|
||||
str: "/surreal/abcum/*/database/*/person/!/f/fullname",
|
||||
obj: &FD{KV: "surreal", NS: "abcum", DB: "database", TB: "person", FD: "fullname"},
|
||||
new: &FD{},
|
||||
},
|
||||
{
|
||||
str: "/surreal/!/r/abcum/database/person/select",
|
||||
obj: &RU{KV: "surreal", NS: "abcum", DB: "database", TB: "person", RU: "select"},
|
||||
new: &RU{},
|
||||
},
|
||||
{
|
||||
str: "/surreal/!/i/abcum/database/person/teenagers",
|
||||
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/*/\x00",
|
||||
obj: &Thing{KV: "surreal", NS: "abcum", DB: "database", TB: "person", ID: Prefix},
|
||||
new: &Thing{},
|
||||
},
|
||||
{
|
||||
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",
|
||||
str: "/surreal/abcum/*/database/*/person/*",
|
||||
obj: &Table{KV: "surreal", NS: "abcum", DB: "database", TB: "person"},
|
||||
new: &Table{},
|
||||
},
|
||||
{
|
||||
str: "/surreal/abcum/database/person/*/\xff",
|
||||
str: "/surreal/abcum/*/database/*/person/*/\x00",
|
||||
obj: &Thing{KV: "surreal", NS: "abcum", DB: "database", TB: "person", ID: Prefix},
|
||||
new: &Thing{},
|
||||
},
|
||||
{
|
||||
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",
|
||||
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",
|
||||
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",
|
||||
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",
|
||||
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",
|
||||
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",
|
||||
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/•/873c2f37-ea03-4c5e-843e-cf393af44155/friend/1987-06-22T08:00:00.123456789Z",
|
||||
obj: &Event{KV: "surreal", NS: "abcum", DB: "database", TB: "person", ID: "873c2f37-ea03-4c5e-843e-cf393af44155", TP: "friend", AT: clock},
|
||||
new: &Event{},
|
||||
},
|
||||
{
|
||||
str: "/surreal/abcum/database/person/«»/873c2f37-ea03-4c5e-843e-cf393af44155/clicked/b38d7aa1-60d6-4f2d-8702-46bd0fa961fe",
|
||||
obj: &Edge{KV: "surreal", NS: "abcum", DB: "database", TB: "person", ID: "873c2f37-ea03-4c5e-843e-cf393af44155", TP: "clicked", FK: "b38d7aa1-60d6-4f2d-8702-46bd0fa961fe"},
|
||||
new: &Edge{},
|
||||
},
|
||||
{
|
||||
str: "/surreal/abcum/database/person/«/873c2f37-ea03-4c5e-843e-cf393af44155/clicked/b38d7aa1-60d6-4f2d-8702-46bd0fa961fe",
|
||||
obj: &Edge{KV: "surreal", NS: "abcum", DB: "database", TB: "person", ID: "873c2f37-ea03-4c5e-843e-cf393af44155", TK: "«", TP: "clicked", FK: "b38d7aa1-60d6-4f2d-8702-46bd0fa961fe"},
|
||||
new: &Edge{},
|
||||
},
|
||||
{
|
||||
str: "/surreal/abcum/database/person/»/873c2f37-ea03-4c5e-843e-cf393af44155/clicked/b38d7aa1-60d6-4f2d-8702-46bd0fa961fe",
|
||||
obj: &Edge{KV: "surreal", NS: "abcum", DB: "database", TB: "person", ID: "873c2f37-ea03-4c5e-843e-cf393af44155", TK: "»", TP: "clicked", FK: "b38d7aa1-60d6-4f2d-8702-46bd0fa961fe"},
|
||||
new: &Edge{},
|
||||
},
|
||||
{
|
||||
str: "/surreal/abcum/database/person/«»/873c2f37-ea03-4c5e-843e-cf393af44155/clicked/b38d7aa1-60d6-4f2d-8702-46bd0fa961fe",
|
||||
obj: &Edge{KV: "surreal", NS: "abcum", DB: "database", TB: "person", ID: "873c2f37-ea03-4c5e-843e-cf393af44155", TK: "«»", TP: "clicked", FK: "b38d7aa1-60d6-4f2d-8702-46bd0fa961fe"},
|
||||
new: &Edge{},
|
||||
},
|
||||
{
|
||||
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/[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"}},
|
||||
new: &Index{},
|
||||
},
|
||||
{
|
||||
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"},
|
||||
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",
|
||||
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 <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"},
|
||||
new: &Point{},
|
||||
},
|
||||
{
|
||||
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{},
|
||||
},
|
||||
{
|
||||
str: "Test key",
|
||||
new: &Full{},
|
||||
|
@ -262,6 +323,9 @@ func TestMain(t *testing.T) {
|
|||
&Thing{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: "b"},
|
||||
&Thing{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: "bB"},
|
||||
&Thing{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: "c"},
|
||||
&Edge{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: "test1", TP: "friend", FK: int8(2)},
|
||||
&Edge{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: "test1", TP: "friend", FK: int8(3)},
|
||||
&Edge{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: "test2", TP: "friend", FK: int8(1)},
|
||||
&Thing{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: "z"},
|
||||
&Thing{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: "Â"},
|
||||
&Thing{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: "Ä"},
|
||||
|
@ -276,10 +340,6 @@ func TestMain(t *testing.T) {
|
|||
&Patch{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: int8(1), AT: time.Now()},
|
||||
&Patch{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: int8(1), AT: time.Now()},
|
||||
|
||||
&Edge{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: int8(1), TP: "friend", FK: int8(2)},
|
||||
&Edge{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: int8(1), TP: "friend", FK: int8(3)},
|
||||
&Edge{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: int8(2), TP: "friend", FK: int8(1)},
|
||||
|
||||
&Index{KV: "kv", NS: "ns", DB: "db", TB: "person", IX: "names", FD: Prefix},
|
||||
|
||||
&Index{KV: "kv", NS: "ns", DB: "db", TB: "person", IX: "names", FD: []interface{}{"account:abcum", false, "Smith", nil, "Zoe"}},
|
||||
|
@ -307,14 +367,14 @@ func TestMain(t *testing.T) {
|
|||
nos []Key
|
||||
}{
|
||||
{
|
||||
obj: &Table{KV: "kv", NS: "ns", DB: "db", TB: "person"},
|
||||
obj: &TB{KV: "kv", NS: "ns", DB: "db", TB: "person"},
|
||||
yes: []Key{
|
||||
&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"}},
|
||||
&Index{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{
|
||||
&Thing{KV: "kv", NS: "ns", DB: "db", TB: "other", ID: "test"},
|
||||
|
@ -323,6 +383,23 @@ func TestMain(t *testing.T) {
|
|||
&Thing{KV: "other", NS: "ns", DB: "db", TB: "person", ID: "test"},
|
||||
},
|
||||
},
|
||||
{
|
||||
obj: &Table{KV: "kv", NS: "ns", DB: "db", TB: "person"},
|
||||
yes: []Key{
|
||||
&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},
|
||||
},
|
||||
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"}},
|
||||
},
|
||||
},
|
||||
{
|
||||
obj: &Thing{KV: "kv", NS: "ns", DB: "db", TB: "person", ID: Ignore},
|
||||
yes: []Key{
|
||||
|
@ -363,30 +440,28 @@ func TestDisplaying(t *testing.T) {
|
|||
for _, test := range tests {
|
||||
|
||||
Convey(test.str, t, func() {
|
||||
|
||||
Convey("String should match", func() {
|
||||
So(test.obj.String(), ShouldEqual, test.str)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestEncoding(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
for i, test := range tests {
|
||||
|
||||
Convey(test.str, t, func() {
|
||||
|
||||
enc := test.obj.Encode()
|
||||
test.new.Decode(enc)
|
||||
|
||||
Convey("Key should encode and decode", func() {
|
||||
Printf("%s\n\n%#q\n\n%v\n\n", test.str, enc, enc)
|
||||
So(test.new, ShouldResemble, test.obj)
|
||||
})
|
||||
|
||||
if i > 0 && i < len(tests)-1 {
|
||||
old := tests[i-1].obj.Encode()
|
||||
So(old, ShouldSortBefore, enc)
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
@ -425,14 +500,9 @@ func TestSorting(t *testing.T) {
|
|||
txt := fmt.Sprintf("%#v", sorts[i-1])
|
||||
|
||||
Convey(txt, t, func() {
|
||||
|
||||
one := sorts[i-1].Encode()
|
||||
two := sorts[i].Encode()
|
||||
|
||||
Convey("Key should sort before next key", func() {
|
||||
Printf("%#v\n%#v\n------\n%#v\n%#v\n------\n%#q\n%#q", sorts[i-1], sorts[i], one, two, one, two)
|
||||
So(string(one), ShouldBeLessThanOrEqualTo, string(two))
|
||||
})
|
||||
So(one, ShouldSortBefore, two)
|
||||
})
|
||||
|
||||
}
|
||||
|
|
43
util/keys/kv.go
Normal file
43
util/keys/kv.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
// 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
|
||||
|
||||
// KV ...
|
||||
type KV struct {
|
||||
KV interface{}
|
||||
}
|
||||
|
||||
// init initialises the key
|
||||
func (k *KV) init() *KV {
|
||||
return k
|
||||
}
|
||||
|
||||
// Encode encodes the key into binary
|
||||
func (k *KV) Encode() []byte {
|
||||
k.init()
|
||||
return encode(k.KV)
|
||||
}
|
||||
|
||||
// Decode decodes the key from binary
|
||||
func (k *KV) Decode(data []byte) {
|
||||
k.init()
|
||||
decode(data, &k.KV)
|
||||
}
|
||||
|
||||
// String returns a string representation of the key
|
||||
func (k *KV) String() string {
|
||||
k.init()
|
||||
return output(k.KV)
|
||||
}
|
|
@ -14,15 +14,9 @@
|
|||
|
||||
package keys
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// LV ...
|
||||
type LV struct {
|
||||
KV interface{}
|
||||
CF interface{}
|
||||
TK interface{}
|
||||
NS interface{}
|
||||
DB interface{}
|
||||
LV interface{}
|
||||
|
@ -30,25 +24,23 @@ type LV struct {
|
|||
|
||||
// init initialises the key
|
||||
func (k *LV) init() *LV {
|
||||
k.CF = "!"
|
||||
k.TK = "l"
|
||||
return k
|
||||
}
|
||||
|
||||
// Encode encodes the key into binary
|
||||
func (k *LV) Encode() []byte {
|
||||
k.init()
|
||||
return encode(k.KV, k.CF, k.TK, k.NS, k.DB, k.LV)
|
||||
return encode(k.KV, k.NS, "*", k.DB, "!", "l", k.LV)
|
||||
}
|
||||
|
||||
// Decode decodes the key from binary
|
||||
func (k *LV) Decode(data []byte) {
|
||||
k.init()
|
||||
decode(data, &k.KV, &k.CF, &k.TK, &k.NS, &k.DB, &k.LV)
|
||||
decode(data, &k.KV, &k.NS, &skip, &k.DB, &skip, &skip, &k.LV)
|
||||
}
|
||||
|
||||
// String returns a string representation of the key
|
||||
func (k *LV) String() string {
|
||||
k.init()
|
||||
return fmt.Sprintf("/%s/%s/%s/%s/%s/%s", k.KV, k.CF, k.TK, k.NS, k.DB, k.LV)
|
||||
return output(k.KV, k.NS, "*", k.DB, "!", "l", k.LV)
|
||||
}
|
||||
|
|
|
@ -14,39 +14,31 @@
|
|||
|
||||
package keys
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// NS ...
|
||||
type NS struct {
|
||||
KV interface{}
|
||||
CF interface{}
|
||||
TK interface{}
|
||||
NS interface{}
|
||||
}
|
||||
|
||||
// init initialises the key
|
||||
func (k *NS) init() *NS {
|
||||
k.CF = "!"
|
||||
k.TK = "n"
|
||||
return k
|
||||
}
|
||||
|
||||
// Encode encodes the key into binary
|
||||
func (k *NS) Encode() []byte {
|
||||
k.init()
|
||||
return encode(k.KV, k.CF, k.TK, k.NS)
|
||||
return encode(k.KV, k.NS)
|
||||
}
|
||||
|
||||
// Decode decodes the key from binary
|
||||
func (k *NS) Decode(data []byte) {
|
||||
k.init()
|
||||
decode(data, &k.KV, &k.CF, &k.TK, &k.NS)
|
||||
decode(data, &k.KV, &k.NS)
|
||||
}
|
||||
|
||||
// String returns a string representation of the key
|
||||
func (k *NS) String() string {
|
||||
k.init()
|
||||
return fmt.Sprintf("/%s/%s/%s/%s", k.KV, k.CF, k.TK, k.NS)
|
||||
return output(k.KV, k.NS)
|
||||
}
|
||||
|
|
45
util/keys/nt.go
Normal file
45
util/keys/nt.go
Normal file
|
@ -0,0 +1,45 @@
|
|||
// 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
|
||||
|
||||
// NT ...
|
||||
type NT struct {
|
||||
KV interface{}
|
||||
NS interface{}
|
||||
TK interface{}
|
||||
}
|
||||
|
||||
// init initialises the key
|
||||
func (k *NT) init() *NT {
|
||||
return k
|
||||
}
|
||||
|
||||
// Encode encodes the key into binary
|
||||
func (k *NT) Encode() []byte {
|
||||
k.init()
|
||||
return encode(k.KV, k.NS, "!", "t", k.TK)
|
||||
}
|
||||
|
||||
// Decode decodes the key from binary
|
||||
func (k *NT) Decode(data []byte) {
|
||||
k.init()
|
||||
decode(data, &k.KV, &k.NS, &skip, &skip, &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)
|
||||
}
|
45
util/keys/nu.go
Normal file
45
util/keys/nu.go
Normal file
|
@ -0,0 +1,45 @@
|
|||
// 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
|
||||
|
||||
// NU ...
|
||||
type NU struct {
|
||||
KV interface{}
|
||||
NS interface{}
|
||||
US interface{}
|
||||
}
|
||||
|
||||
// init initialises the key
|
||||
func (k *NU) init() *NU {
|
||||
return k
|
||||
}
|
||||
|
||||
// Encode encodes the key into binary
|
||||
func (k *NU) Encode() []byte {
|
||||
k.init()
|
||||
return encode(k.KV, k.NS, "!", "u", k.US)
|
||||
}
|
||||
|
||||
// Decode decodes the key from binary
|
||||
func (k *NU) Decode(data []byte) {
|
||||
k.init()
|
||||
decode(data, &k.KV, &k.NS, &skip, &skip, &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)
|
||||
}
|
30
util/keys/output.go
Normal file
30
util/keys/output.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
// 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
|
||||
|
||||
import "fmt"
|
||||
|
||||
// output decodes an encoded string using the unicode collation algorithm.
|
||||
func output(items ...interface{}) (out string) {
|
||||
for _, v := range items {
|
||||
switch v.(type) {
|
||||
default:
|
||||
out = out + fmt.Sprintf("/%s", v)
|
||||
case []interface{}:
|
||||
out = out + fmt.Sprintf("/%v", v)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
|
@ -15,7 +15,6 @@
|
|||
package keys
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -25,14 +24,12 @@ type Patch struct {
|
|||
NS interface{}
|
||||
DB interface{}
|
||||
TB interface{}
|
||||
TK interface{}
|
||||
ID interface{}
|
||||
AT time.Time
|
||||
}
|
||||
|
||||
// init initialises the key
|
||||
func (k *Patch) init() *Patch {
|
||||
k.TK = "~"
|
||||
if k.AT.IsZero() {
|
||||
k.AT = time.Now()
|
||||
}
|
||||
|
@ -42,17 +39,17 @@ func (k *Patch) init() *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.TK, 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()
|
||||
decode(data, &k.KV, &k.NS, &k.DB, &k.TB, &k.TK, &k.ID, &k.AT)
|
||||
decode(data, &k.KV, &k.NS, &skip, &k.DB, &skip, &k.TB, &skip, &k.ID, &k.AT)
|
||||
}
|
||||
|
||||
// String returns a string representation of the key
|
||||
func (k *Patch) String() string {
|
||||
k.init()
|
||||
return fmt.Sprintf("/%s/%s/%s/%s/%s/%s/%s", k.KV, k.NS, k.DB, k.TB, k.TK, k.ID, k.AT.Format(time.RFC3339Nano))
|
||||
return output(k.KV, k.NS, "*", k.DB, "*", k.TB, "~", k.ID, k.AT.Format(time.RFC3339Nano))
|
||||
}
|
||||
|
|
|
@ -14,17 +14,12 @@
|
|||
|
||||
package keys
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Point ...
|
||||
type Point struct {
|
||||
KV interface{}
|
||||
NS interface{}
|
||||
DB interface{}
|
||||
TB interface{}
|
||||
TK interface{}
|
||||
IX interface{}
|
||||
FD interface{}
|
||||
ID interface{}
|
||||
|
@ -32,24 +27,23 @@ type Point struct {
|
|||
|
||||
// init initialises the key
|
||||
func (k *Point) init() *Point {
|
||||
k.TK = "∆"
|
||||
return k
|
||||
}
|
||||
|
||||
// Encode encodes the key into binary
|
||||
func (k *Point) Encode() []byte {
|
||||
k.init()
|
||||
return encode(k.KV, k.NS, k.DB, k.TB, k.TK, 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()
|
||||
decode(data, &k.KV, &k.NS, &k.DB, &k.TB, &k.TK, &k.IX, &k.FD, &k.ID)
|
||||
decode(data, &k.KV, &k.NS, &skip, &k.DB, &skip, &k.TB, &skip, &k.IX, &k.FD, &k.ID)
|
||||
}
|
||||
|
||||
// String returns a string representation of the key
|
||||
func (k *Point) String() string {
|
||||
k.init()
|
||||
return fmt.Sprintf("/%s/%s/%s/%s/%s/%s/%v/%s", k.KV, k.NS, k.DB, k.TB, k.TK, k.IX, k.FD, k.ID)
|
||||
return output(k.KV, k.NS, "*", k.DB, "*", k.TB, "¤", k.IX, k.FD, k.ID)
|
||||
}
|
||||
|
|
|
@ -14,15 +14,9 @@
|
|||
|
||||
package keys
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// SC ...
|
||||
type SC struct {
|
||||
KV interface{}
|
||||
CF interface{}
|
||||
TK interface{}
|
||||
NS interface{}
|
||||
DB interface{}
|
||||
SC interface{}
|
||||
|
@ -30,25 +24,23 @@ type SC struct {
|
|||
|
||||
// init initialises the key
|
||||
func (k *SC) init() *SC {
|
||||
k.CF = "!"
|
||||
k.TK = "s"
|
||||
return k
|
||||
}
|
||||
|
||||
// Encode encodes the key into binary
|
||||
func (k *SC) Encode() []byte {
|
||||
k.init()
|
||||
return encode(k.KV, k.CF, k.TK, k.NS, k.DB, 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()
|
||||
decode(data, &k.KV, &k.CF, &k.TK, &k.NS, &k.DB, &k.SC)
|
||||
decode(data, &k.KV, &k.NS, &skip, &k.DB, &skip, &skip, &k.SC)
|
||||
}
|
||||
|
||||
// String returns a string representation of the key
|
||||
func (k *SC) String() string {
|
||||
k.init()
|
||||
return fmt.Sprintf("/%s/%s/%s/%s/%s/%s", k.KV, k.CF, k.TK, k.NS, k.DB, k.SC)
|
||||
return output(k.KV, k.NS, "*", k.DB, "!", "s", k.SC)
|
||||
}
|
||||
|
|
47
util/keys/st.go
Normal file
47
util/keys/st.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
// 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
|
||||
|
||||
// ST ...
|
||||
type ST struct {
|
||||
KV interface{}
|
||||
NS interface{}
|
||||
DB interface{}
|
||||
SC interface{}
|
||||
TK interface{}
|
||||
}
|
||||
|
||||
// init initialises the key
|
||||
func (k *ST) init() *ST {
|
||||
return k
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
// Decode decodes the key from binary
|
||||
func (k *ST) Decode(data []byte) {
|
||||
k.init()
|
||||
decode(data, &k.KV, &k.NS, &skip, &k.DB, &skip, &skip, &k.SC, &skip, &skip, &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)
|
||||
}
|
|
@ -14,10 +14,6 @@
|
|||
|
||||
package keys
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Table ...
|
||||
type Table struct {
|
||||
KV interface{}
|
||||
|
@ -34,17 +30,17 @@ func (k *Table) init() *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()
|
||||
decode(data, &k.KV, &k.NS, &k.DB, &k.TB)
|
||||
decode(data, &k.KV, &k.NS, &skip, &k.DB, &skip, &k.TB, &skip)
|
||||
}
|
||||
|
||||
// String returns a string representation of the key
|
||||
func (k *Table) String() string {
|
||||
k.init()
|
||||
return fmt.Sprintf("/%s/%s/%s/%s", k.KV, k.NS, k.DB, k.TB)
|
||||
return output(k.KV, k.NS, "*", k.DB, "*", k.TB, "*")
|
||||
}
|
||||
|
|
|
@ -14,15 +14,9 @@
|
|||
|
||||
package keys
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// TB ...
|
||||
type TB struct {
|
||||
KV interface{}
|
||||
CF interface{}
|
||||
TK interface{}
|
||||
NS interface{}
|
||||
DB interface{}
|
||||
TB interface{}
|
||||
|
@ -30,25 +24,23 @@ type TB struct {
|
|||
|
||||
// init initialises the key
|
||||
func (k *TB) init() *TB {
|
||||
k.CF = "!"
|
||||
k.TK = "t"
|
||||
return k
|
||||
}
|
||||
|
||||
// Encode encodes the key into binary
|
||||
func (k *TB) Encode() []byte {
|
||||
k.init()
|
||||
return encode(k.KV, k.CF, k.TK, k.NS, k.DB, k.TB)
|
||||
return encode(k.KV, k.NS, "*", k.DB, "*", k.TB)
|
||||
}
|
||||
|
||||
// Decode decodes the key from binary
|
||||
func (k *TB) Decode(data []byte) {
|
||||
k.init()
|
||||
decode(data, &k.KV, &k.CF, &k.TK, &k.NS, &k.DB, &k.TB)
|
||||
decode(data, &k.KV, &k.NS, &skip, &k.DB, &skip, &k.TB)
|
||||
}
|
||||
|
||||
// String returns a string representation of the key
|
||||
func (k *TB) String() string {
|
||||
k.init()
|
||||
return fmt.Sprintf("/%s/%s/%s/%s/%s/%s", k.KV, k.CF, k.TK, k.NS, k.DB, k.TB)
|
||||
return output(k.KV, k.NS, "*", k.DB, "*", k.TB)
|
||||
}
|
||||
|
|
|
@ -14,40 +14,34 @@
|
|||
|
||||
package keys
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Thing ...
|
||||
type Thing struct {
|
||||
KV interface{}
|
||||
NS interface{}
|
||||
DB interface{}
|
||||
TB interface{}
|
||||
TK interface{}
|
||||
ID interface{}
|
||||
}
|
||||
|
||||
// init initialises the key
|
||||
func (k *Thing) init() *Thing {
|
||||
k.TK = "*"
|
||||
return k
|
||||
}
|
||||
|
||||
// Encode encodes the key into binary
|
||||
func (k *Thing) Encode() []byte {
|
||||
k.init()
|
||||
return encode(k.KV, k.NS, k.DB, k.TB, k.TK, 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()
|
||||
decode(data, &k.KV, &k.NS, &k.DB, &k.TB, &k.TK, &k.ID)
|
||||
decode(data, &k.KV, &k.NS, &skip, &k.DB, &skip, &k.TB, &skip, &k.ID)
|
||||
}
|
||||
|
||||
// String returns a string representation of the key
|
||||
func (k *Thing) String() string {
|
||||
k.init()
|
||||
return fmt.Sprintf("/%s/%s/%s/%s/%s/%s", k.KV, k.NS, k.DB, k.TB, k.TK, k.ID)
|
||||
return output(k.KV, k.NS, "*", k.DB, "*", k.TB, "*", k.ID)
|
||||
}
|
||||
|
|
|
@ -14,15 +14,9 @@
|
|||
|
||||
package keys
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// VW ...
|
||||
type VW struct {
|
||||
KV interface{}
|
||||
CF interface{}
|
||||
TK interface{}
|
||||
NS interface{}
|
||||
DB interface{}
|
||||
VW interface{}
|
||||
|
@ -30,25 +24,23 @@ type VW struct {
|
|||
|
||||
// init initialises the key
|
||||
func (k *VW) init() *VW {
|
||||
k.CF = "!"
|
||||
k.TK = "v"
|
||||
return k
|
||||
}
|
||||
|
||||
// Encode encodes the key into binary
|
||||
func (k *VW) Encode() []byte {
|
||||
k.init()
|
||||
return encode(k.KV, k.CF, k.TK, k.NS, k.DB, k.VW)
|
||||
return encode(k.KV, k.NS, "*", k.DB, "!", "v", k.VW)
|
||||
}
|
||||
|
||||
// Decode decodes the key from binary
|
||||
func (k *VW) Decode(data []byte) {
|
||||
k.init()
|
||||
decode(data, &k.KV, &k.CF, &k.TK, &k.NS, &k.DB, &k.VW)
|
||||
decode(data, &k.KV, &k.NS, &skip, &k.DB, &skip, &skip, &k.VW)
|
||||
}
|
||||
|
||||
// String returns a string representation of the key
|
||||
func (k *VW) String() string {
|
||||
k.init()
|
||||
return fmt.Sprintf("/%s/%s/%s/%s/%s/%s", k.KV, k.CF, k.TK, k.NS, k.DB, k.VW)
|
||||
return output(k.KV, k.NS, "*", k.DB, "!", "v", k.VW)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue