Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
2c2d8424b3 | |||
e31f75cb63 |
31
boltease.go
31
boltease.go
@@ -576,6 +576,11 @@ func (b *DB) SetStringList(path, values []string) error {
|
||||
defer b.CloseDB()
|
||||
}
|
||||
|
||||
// We remove the bucket, if it already exists
|
||||
bktPth, bktNm := path[:len(path)-2], path[len(path)-1]
|
||||
fmt.Println("Deleting Bucket:", bktPth, bktNm)
|
||||
b.DeleteBucket(bktPth, bktNm)
|
||||
|
||||
err = b.MkBucketPath(path)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -593,10 +598,6 @@ func (b *DB) SetStringList(path, values []string) error {
|
||||
}
|
||||
|
||||
// bkt should have the last bucket in the path
|
||||
// We need to get the sequence number, if it's greater than the length
|
||||
// of 'values', we're going to have to delete values.
|
||||
seq := bkt.Sequence()
|
||||
bkt.SetSequence(0)
|
||||
for _, v := range values {
|
||||
id, _ := bkt.NextSequence()
|
||||
bId := make([]byte, 8)
|
||||
@@ -606,15 +607,6 @@ func (b *DB) SetStringList(path, values []string) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
currSeq := bkt.Sequence()
|
||||
for ; seq < currSeq; seq++ {
|
||||
bId := make([]byte, 8)
|
||||
binary.BigEndian.PutUint64(bId, seq)
|
||||
err = bkt.Delete(bId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return err
|
||||
@@ -660,6 +652,19 @@ func (b *DB) AddToStringList(path []string, values ...string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (b *DB) StringListContains(path []string, value string) (bool, error) {
|
||||
list, err := b.GetStringList(path)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
for i := range list {
|
||||
if list[i] == value {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// GetKeyValueMap returns a map of all key/value pairs in the bucket at path
|
||||
func (b *DB) GetKeyValueMap(path []string) (map[string][]byte, error) {
|
||||
var err error
|
||||
|
Reference in New Issue
Block a user