Rename store Namespace / Prefix options to Database and Table (#1492)
* Rename Namespace to DB, Rename Prefix to table, Remove Suffix Option * Rename options * Rename options * Add store_table option * Table per service, not Database per service
This commit is contained in:
@@ -83,14 +83,11 @@ func (m *memoryStore) Read(key string, opts ...store.ReadOption) ([]*store.Recor
|
||||
}
|
||||
|
||||
func (m *memoryStore) get(k string) (*store.Record, error) {
|
||||
if len(m.options.Suffix) > 0 {
|
||||
k = k + m.options.Suffix
|
||||
if len(m.options.Table) > 0 {
|
||||
k = m.options.Table + "/" + k
|
||||
}
|
||||
if len(m.options.Prefix) > 0 {
|
||||
k = m.options.Prefix + "/" + k
|
||||
}
|
||||
if len(m.options.Namespace) > 0 {
|
||||
k = m.options.Namespace + "/" + k
|
||||
if len(m.options.Database) > 0 {
|
||||
k = m.options.Database + "/" + k
|
||||
}
|
||||
var storedRecord *internalRecord
|
||||
r, found := m.store.Get(k)
|
||||
@@ -142,14 +139,11 @@ func (m *memoryStore) Write(r *store.Record, opts ...store.WriteOption) error {
|
||||
|
||||
func (m *memoryStore) set(r *store.Record) {
|
||||
key := r.Key
|
||||
if len(m.options.Suffix) > 0 {
|
||||
key = key + m.options.Suffix
|
||||
if len(m.options.Table) > 0 {
|
||||
key = m.options.Table + "/" + key
|
||||
}
|
||||
if len(m.options.Prefix) > 0 {
|
||||
key = m.options.Prefix + "/" + key
|
||||
}
|
||||
if len(m.options.Namespace) > 0 {
|
||||
key = m.options.Namespace + "/" + key
|
||||
if len(m.options.Database) > 0 {
|
||||
key = m.options.Database + "/" + key
|
||||
}
|
||||
|
||||
// copy the incoming record and then
|
||||
@@ -175,14 +169,11 @@ func (m *memoryStore) Delete(key string, opts ...store.DeleteOption) error {
|
||||
}
|
||||
|
||||
func (m *memoryStore) delete(key string) {
|
||||
if len(m.options.Suffix) > 0 {
|
||||
key = key + m.options.Suffix
|
||||
if len(m.options.Table) > 0 {
|
||||
key = m.options.Table + "/" + key
|
||||
}
|
||||
if len(m.options.Prefix) > 0 {
|
||||
key = m.options.Prefix + "/" + key
|
||||
}
|
||||
if len(m.options.Namespace) > 0 {
|
||||
key = m.options.Namespace + "/" + key
|
||||
if len(m.options.Database) > 0 {
|
||||
key = m.options.Database + "/" + key
|
||||
}
|
||||
m.store.Delete(key)
|
||||
}
|
||||
@@ -226,14 +217,11 @@ func (m *memoryStore) list(limit, offset uint) []string {
|
||||
allKeys := make([]string, len(allItems))
|
||||
i := 0
|
||||
for k := range allItems {
|
||||
if len(m.options.Suffix) > 0 {
|
||||
k = strings.TrimSuffix(k, m.options.Suffix)
|
||||
if len(m.options.Database) > 0 {
|
||||
k = strings.TrimPrefix(k, m.options.Database+"/")
|
||||
}
|
||||
if len(m.options.Namespace) > 0 {
|
||||
k = strings.TrimPrefix(k, m.options.Namespace+"/")
|
||||
}
|
||||
if len(m.options.Prefix) > 0 {
|
||||
k = strings.TrimPrefix(k, m.options.Prefix+"/")
|
||||
if len(m.options.Table) > 0 {
|
||||
k = strings.TrimPrefix(k, m.options.Table+"/")
|
||||
}
|
||||
allKeys[i] = k
|
||||
i++
|
||||
|
@@ -10,9 +10,9 @@ import (
|
||||
)
|
||||
|
||||
func TestMemoryReInit(t *testing.T) {
|
||||
s := NewStore(store.Prefix("aaa"))
|
||||
s.Init(store.Prefix(""))
|
||||
if len(s.Options().Prefix) > 0 {
|
||||
s := NewStore(store.Table("aaa"))
|
||||
s.Init(store.Table(""))
|
||||
if len(s.Options().Table) > 0 {
|
||||
t.Error("Init didn't reinitialise the store")
|
||||
}
|
||||
}
|
||||
@@ -25,31 +25,19 @@ func TestMemoryBasic(t *testing.T) {
|
||||
|
||||
func TestMemoryPrefix(t *testing.T) {
|
||||
s := NewStore()
|
||||
s.Init(store.Prefix("some-prefix"))
|
||||
basictest(s, t)
|
||||
}
|
||||
|
||||
func TestMemorySuffix(t *testing.T) {
|
||||
s := NewStore()
|
||||
s.Init(store.Suffix("some-suffix"))
|
||||
basictest(s, t)
|
||||
}
|
||||
|
||||
func TestMemoryPrefixSuffix(t *testing.T) {
|
||||
s := NewStore()
|
||||
s.Init(store.Prefix("some-prefix"), store.Prefix("some-suffix"))
|
||||
s.Init(store.Table("some-prefix"))
|
||||
basictest(s, t)
|
||||
}
|
||||
|
||||
func TestMemoryNamespace(t *testing.T) {
|
||||
s := NewStore()
|
||||
s.Init(store.Namespace("some-namespace"))
|
||||
s.Init(store.Database("some-namespace"))
|
||||
basictest(s, t)
|
||||
}
|
||||
|
||||
func TestMemoryNamespacePrefix(t *testing.T) {
|
||||
s := NewStore()
|
||||
s.Init(store.Prefix("some-prefix"), store.Namespace("some-namespace"))
|
||||
s.Init(store.Table("some-prefix"), store.Database("some-namespace"))
|
||||
basictest(s, t)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user