Make sure LV database key specifies a table

This commit is contained in:
Tobie Morgan Hitchcock 2017-11-16 20:12:58 +00:00
parent 6a1ec1b2bb
commit 21cb197d5a
2 changed files with 10 additions and 8 deletions

View file

@ -105,11 +105,6 @@ func TestMain(t *testing.T) {
obj: &DB{KV: "surreal", NS: "abcum", DB: "database"}, obj: &DB{KV: "surreal", NS: "abcum", DB: "database"},
new: &DB{}, new: &DB{},
}, },
{
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", str: "/surreal/abcum/*/database/!/s/admin",
obj: &SC{KV: "surreal", NS: "abcum", DB: "database", SC: "admin"}, obj: &SC{KV: "surreal", NS: "abcum", DB: "database", SC: "admin"},
@ -145,6 +140,11 @@ func TestMain(t *testing.T) {
obj: &IX{KV: "surreal", NS: "abcum", DB: "database", TB: "person", IX: "teenagers"}, obj: &IX{KV: "surreal", NS: "abcum", DB: "database", TB: "person", IX: "teenagers"},
new: &IX{}, 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/*", str: "/surreal/abcum/*/database/*/person/*",
obj: &Table{KV: "surreal", NS: "abcum", DB: "database", TB: "person"}, obj: &Table{KV: "surreal", NS: "abcum", DB: "database", TB: "person"},

View file

@ -19,6 +19,7 @@ type LV struct {
KV string KV string
NS string NS string
DB string DB string
TB string
LV string LV string
} }
@ -33,6 +34,7 @@ func (k *LV) Copy() *LV {
KV: k.KV, KV: k.KV,
NS: k.NS, NS: k.NS,
DB: k.DB, DB: k.DB,
TB: k.TB,
LV: k.LV, LV: k.LV,
} }
} }
@ -40,17 +42,17 @@ func (k *LV) Copy() *LV {
// Encode encodes the key into binary // Encode encodes the key into binary
func (k *LV) Encode() []byte { func (k *LV) Encode() []byte {
k.init() k.init()
return encode(k.KV, k.NS, "*", k.DB, "!", "l", k.LV) return encode(k.KV, k.NS, "*", k.DB, "*", k.TB, "!", "l", k.LV)
} }
// Decode decodes the key from binary // Decode decodes the key from binary
func (k *LV) Decode(data []byte) { func (k *LV) Decode(data []byte) {
k.init() k.init()
decode(data, &k.KV, &k.NS, &skip, &k.DB, &skip, &skip, &k.LV) decode(data, &k.KV, &k.NS, &skip, &k.DB, &skip, &k.TB, &skip, &skip, &k.LV)
} }
// String returns a string representation of the key // String returns a string representation of the key
func (k *LV) String() string { func (k *LV) String() string {
k.init() k.init()
return output(k.KV, k.NS, "*", k.DB, "!", "l", k.LV) return output(k.KV, k.NS, "*", k.DB, "*", k.TB, "!", "l", k.LV)
} }