aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal/db/store.go
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2019-03-15 15:03:01 -0700
committerKiran Kamineni <kiran.k.kamineni@intel.com>2019-03-25 14:41:34 -0700
commit037cfda2181e4995e4e2a47db6f1121b532b686b (patch)
treef9cb838fc5cc037c01a9f55f561c3b5621236667 /src/k8splugin/internal/db/store.go
parent8cdd50b6a06aef5cb0541e74a07b10bd4b01b589 (diff)
Add support for composite keys
Composite keys help us store objects which are unique for a given set of pre-existing objects. Eg: Many profiles can exist for a definition and its key will have a definition name as a part of the composite key. P2: Use a predefined interface for keys instead of generic interfaceP{} P3: Add check for empty strings in stringer interface P5: Add appropriate keys in other packages. Issue-ID: MULTICLOUD-531 Change-Id: I314b1fbd718489ae8a45f0f38915c08ca32f9f43 Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'src/k8splugin/internal/db/store.go')
-rw-r--r--src/k8splugin/internal/db/store.go15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/k8splugin/internal/db/store.go b/src/k8splugin/internal/db/store.go
index a235597a..148e078e 100644
--- a/src/k8splugin/internal/db/store.go
+++ b/src/k8splugin/internal/db/store.go
@@ -23,6 +23,13 @@ import (
// DBconn interface used to talk a concrete Database connection
var DBconn Store
+// Key is an interface that will be implemented by anypackage
+// that wants to use the Store interface. This allows various
+// db backends and key types.
+type Key interface {
+ String() string
+}
+
// Store is an interface for accessing a database
type Store interface {
// Returns nil if db health is good
@@ -33,19 +40,19 @@ type Store interface {
// Creates a new master table with key and links data with tag and
// creates a pointer to the newly added data in the master table
- Create(table, key, tag string, data interface{}) error
+ Create(table string, key Key, tag string, data interface{}) error
// Reads data for a particular key with specific tag.
- Read(table, key, tag string) ([]byte, error)
+ Read(table string, key Key, tag string) ([]byte, error)
//TODO: Update(context.Context, string, interface{}) error
// Deletes a specific tag data for key.
// TODO: If tag is empty, it will delete all tags under key.
- Delete(table, key, tag string) error
+ Delete(table string, key Key, tag string) error
// Reads all master tables and data from the specified tag in table
- ReadAll(table, tag string) (map[string][]byte, error)
+ ReadAll(table string, tag string) (map[string][]byte, error)
}
// CreateDBClient creates the DB client