working on List

This commit is contained in:
bel
2019-06-21 17:13:18 -06:00
parent 6ac77d247e
commit ade973d19d
13 changed files with 178 additions and 2 deletions

19
bolt.go
View File

@@ -13,6 +13,25 @@ func NewBolt(path string) (*Bolt, error) {
}, err
}
func (b *Bolt) List(ns []string, limits ...string) ([]string, error) {
namespace := resolveNamespace(ns)
limits = resolveLimits(limits)
found := []string{}
err := b.db.View(func(tx *bolt.Tx) error {
bucket := tx.Bucket([]byte(namespace))
if bucket == nil {
return nil
}
c := bucket.Cursor()
for k, _ := c.Seek([]byte(limits[0])); k != nil; k, _ = c.Next() {
found = append(found, string(k))
}
return nil
})
return found, err
}
func (b *Bolt) Get(key string, ns ...string) ([]byte, error) {
namespace := resolveNamespace(ns)
var result []byte