Implement list and fix test
This commit is contained in:
15
leveldb.go
15
leveldb.go
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user