From 21cb197d5ac17935e1b34bd9d7d155e5779cf6a3 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Thu, 16 Nov 2017 20:12:58 +0000 Subject: [PATCH] Make sure LV database key specifies a table --- util/keys/keys_test.go | 10 +++++----- util/keys/lv.go | 8 +++++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/util/keys/keys_test.go b/util/keys/keys_test.go index 6ad54a5d..ccac3abb 100644 --- a/util/keys/keys_test.go +++ b/util/keys/keys_test.go @@ -105,11 +105,6 @@ func TestMain(t *testing.T) { obj: &DB{KV: "surreal", NS: "abcum", DB: "database"}, 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", 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"}, 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/*", obj: &Table{KV: "surreal", NS: "abcum", DB: "database", TB: "person"}, diff --git a/util/keys/lv.go b/util/keys/lv.go index eec150af..29fadc9b 100644 --- a/util/keys/lv.go +++ b/util/keys/lv.go @@ -19,6 +19,7 @@ type LV struct { KV string NS string DB string + TB string LV string } @@ -33,6 +34,7 @@ func (k *LV) Copy() *LV { KV: k.KV, NS: k.NS, DB: k.DB, + TB: k.TB, LV: k.LV, } } @@ -40,17 +42,17 @@ 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, "!", "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() - 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 func (k *LV) String() string { 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) }