Implement list and fix test

This commit is contained in:
bel
2019-06-21 17:57:00 -06:00
parent ade973d19d
commit 52479ed8a0
12 changed files with 161 additions and 29 deletions

View File

@@ -23,12 +23,23 @@ func NewLevelDB(path string) (*LevelDB, error) {
}
func (ldb *LevelDB) List(ns []string, limits ...string) ([]string, error) {
namespace := resolveNamespace(ns)
limits = resolveLimits(limits)
limits[0] = path.Join(namespace, limits[0])
limits[1] = path.Join(namespace, limits[1])
keys := []string{}
r := util.BytesPrefix([]byte{})
r := util.BytesPrefix([]byte(namespace))
it := ldb.db.NewIterator(r, nil)
defer it.Release()
for it.Next() {
keys = append(keys, string(it.Key()))
k := string(it.Key())
if k < limits[0] {
continue
} else if k > limits[1] {
break
}
keys = append(keys, k)
}
err := it.Error()
return keys, err