map default namespace try

This commit is contained in:
Bel LaPointe
2019-11-12 13:38:20 -07:00
parent f807cc71b2
commit 283c2dffd2
17 changed files with 10 additions and 22 deletions

7
leveldb.go Normal file → Executable file
View File

@@ -68,8 +68,13 @@ func (ldb *LevelDB) Get(key string, ns ...string) ([]byte, error) {
func (ldb *LevelDB) Set(key string, value []byte, ns ...string) error {
namespace := resolveNamespace(ns)
key = path.Join(namespace, key)
batch := &leveldb.Batch{}
batch.Put([]byte(path.Join(namespace, key)), value)
if value != nil {
batch.Put([]byte(key), value)
} else {
batch.Delete([]byte(key))
}
return ldb.db.Write(batch, nil)
}