diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-02-16 14:00:32 -0700 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-02-16 14:00:32 -0700 |
commit | f8fd84b2be54c2ca900521f5ca51a811bdb2a2c3 (patch) | |
tree | fbdf8f185404a1eaa92c927bf0fce63126b69f5f /db.go | |
parent | Add CreateBucketIfNotExists(). (diff) | |
parent | Add Transaction.ForEach(). (diff) | |
download | dedo-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.go | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -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) { |