diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2015-03-18 10:11:07 -0600 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2015-03-18 10:11:07 -0600 |
commit | 4d30731e9122988d2012a9574c43f80f054a0d3b (patch) | |
tree | f372d05b04e985b1f3baf13eb9c1cad0c81a9974 /db_test.go | |
parent | Merge pull request #328 from baijum/bolt-article (diff) | |
parent | Add transaction batching (diff) | |
download | dedo-4d30731e9122988d2012a9574c43f80f054a0d3b.tar.gz dedo-4d30731e9122988d2012a9574c43f80f054a0d3b.tar.xz |
Merge pull request #285 from tv42/batch
Add transaction batching
Diffstat (limited to 'db_test.go')
-rw-r--r-- | db_test.go | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -618,6 +618,34 @@ func NewTestDB() *TestDB { return &TestDB{db} } +// MustView executes a read-only function. Panic on error. +func (db *TestDB) MustView(fn func(tx *bolt.Tx) error) { + if err := db.DB.View(func(tx *bolt.Tx) error { + return fn(tx) + }); err != nil { + panic(err.Error()) + } +} + +// MustUpdate executes a read-write function. Panic on error. +func (db *TestDB) MustUpdate(fn func(tx *bolt.Tx) error) { + if err := db.DB.View(func(tx *bolt.Tx) error { + return fn(tx) + }); err != nil { + panic(err.Error()) + } +} + +// MustCreateBucket creates a new bucket. Panic on error. +func (db *TestDB) MustCreateBucket(name []byte) { + if err := db.Update(func(tx *bolt.Tx) error { + _, err := tx.CreateBucket([]byte(name)) + return err + }); err != nil { + panic(err.Error()) + } +} + // Close closes the database and deletes the underlying file. func (db *TestDB) Close() { // Log statistics. |