From 61015c8f7a0b2c88fe513522b6969aec4f7ea048 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Thu, 16 Nov 2017 20:14:44 +0000 Subject: [PATCH] Add database key for FT foreign tables --- util/keys/ft.go | 57 ++++++++++++++++++++++++++++++++++++++++++ util/keys/keys_test.go | 5 ++++ 2 files changed, 62 insertions(+) create mode 100644 util/keys/ft.go diff --git a/util/keys/ft.go b/util/keys/ft.go new file mode 100644 index 00000000..fdb4e822 --- /dev/null +++ b/util/keys/ft.go @@ -0,0 +1,57 @@ +// 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 + +// FT ... +type FT struct { + KV string + NS string + DB string + TB string + FT string +} + +// init initialises the key +func (k *FT) init() *FT { + return k +} + +func (k *FT) Copy() *FT { + return &FT{ + KV: k.KV, + NS: k.NS, + DB: k.DB, + TB: k.TB, + FT: k.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) +} + +// Decode decodes the key from binary +func (k *FT) Decode(data []byte) { + k.init() + decode(data, &k.KV, &k.NS, &skip, &k.DB, &skip, &k.TB, &skip, &skip, &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) +} diff --git a/util/keys/keys_test.go b/util/keys/keys_test.go index fa985058..0859431a 100644 --- a/util/keys/keys_test.go +++ b/util/keys/keys_test.go @@ -150,6 +150,11 @@ func TestMain(t *testing.T) { obj: &LV{KV: "surreal", NS: "abcum", DB: "database", TB: "person", LV: "realtime"}, new: &LV{}, }, + { + str: "/surreal/abcum/*/database/*/person/!/t/foreign", + obj: &FT{KV: "surreal", NS: "abcum", DB: "database", TB: "person", FT: "foreign"}, + new: &FT{}, + }, { str: "/surreal/abcum/*/database/*/person/*", obj: &Table{KV: "surreal", NS: "abcum", DB: "database", TB: "person"},