aboutsummaryrefslogtreecommitdiff
path: root/db.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-02-16 14:00:32 -0700
committerBen Johnson <benbjohnson@yahoo.com>2014-02-16 14:00:32 -0700
commitf8fd84b2be54c2ca900521f5ca51a811bdb2a2c3 (patch)
treefbdf8f185404a1eaa92c927bf0fce63126b69f5f /db.go
parentAdd CreateBucketIfNotExists(). (diff)
parentAdd Transaction.ForEach(). (diff)
downloaddedo-f8fd84b2be54c2ca900521f5ca51a811bdb2a2c3.tar.gz
dedo-f8fd84b2be54c2ca900521f5ca51a811bdb2a2c3.tar.xz
Merge pull request #36 from benbjohnson/for-each
ForEach()
Diffstat (limited to 'db.go')
-rw-r--r--db.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/db.go b/db.go
index a519f73..0276d7a 100644
--- a/db.go
+++ b/db.go
@@ -359,6 +359,17 @@ func (db *DB) Do(fn func(*RWTransaction) error) error {
return t.Commit()
}
+// ForEach executes a function for each key/value pair in a bucket.
+// An error is returned if the bucket cannot be found.
+func (db *DB) ForEach(name string, fn func(k, v []byte) error) error {
+ t, err := db.Transaction()
+ if err != nil {
+ return err
+ }
+ defer t.Close()
+ return t.ForEach(name, fn)
+}
+
// Bucket retrieves a reference to a bucket.
// This is typically useful for checking the existence of a bucket.
func (db *DB) Bucket(name string) (*Bucket, error) {