aboutsummaryrefslogtreecommitdiff
path: root/example_test.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-02-22 23:08:30 -0700
committerBen Johnson <benbjohnson@yahoo.com>2014-02-23 08:32:53 -0700
commita544249dd8fb2ff76215a2563c2b8f3ab2ccffdb (patch)
treeaf6b03c1922dfd8805b10343a5c52835aa49b743 /example_test.go
parentRevert "Refactor Transaction/Bucket API." (diff)
downloaddedo-a544249dd8fb2ff76215a2563c2b8f3ab2ccffdb.tar.gz
dedo-a544249dd8fb2ff76215a2563c2b8f3ab2ccffdb.tar.xz
Refactor Bucket.
Diffstat (limited to 'example_test.go')
-rw-r--r--example_test.go17
1 files changed, 10 insertions, 7 deletions
diff --git a/example_test.go b/example_test.go
index 8747f94..b4fac38 100644
--- a/example_test.go
+++ b/example_test.go
@@ -71,7 +71,8 @@ func ExampleDB_Do() {
if err := t.CreateBucket("widgets"); err != nil {
return err
}
- if err := t.Put("widgets", []byte("foo"), []byte("bar")); err != nil {
+ b := t.Bucket("widgets")
+ if err := b.Put([]byte("foo"), []byte("bar")); err != nil {
return err
}
return nil
@@ -100,7 +101,7 @@ func ExampleDB_With() {
// Access data from within a read-only transactional block.
db.With(func(t *Transaction) error {
- v, _ := t.Get("people", []byte("john"))
+ v := t.Bucket("people").Get([]byte("john"))
fmt.Printf("John's last name is %s.\n", string(v))
return nil
})
@@ -144,14 +145,15 @@ func ExampleRWTransaction() {
// Create several keys in a transaction.
rwtxn, _ := db.RWTransaction()
- rwtxn.Put("widgets", []byte("john"), []byte("blue"))
- rwtxn.Put("widgets", []byte("abby"), []byte("red"))
- rwtxn.Put("widgets", []byte("zephyr"), []byte("purple"))
+ b := rwtxn.Bucket("widgets")
+ b.Put([]byte("john"), []byte("blue"))
+ b.Put([]byte("abby"), []byte("red"))
+ b.Put([]byte("zephyr"), []byte("purple"))
rwtxn.Commit()
// Iterate over the values in sorted key order.
txn, _ := db.Transaction()
- c, _ := txn.Cursor("widgets")
+ c := txn.Bucket("widgets").Cursor()
for k, v := c.First(); k != nil; k, v = c.Next() {
fmt.Printf("%s likes %s\n", string(k), string(v))
}
@@ -177,7 +179,8 @@ func ExampleRWTransaction_rollback() {
// Update the key but rollback the transaction so it never saves.
rwtxn, _ := db.RWTransaction()
- rwtxn.Put("widgets", []byte("foo"), []byte("baz"))
+ b := rwtxn.Bucket("widgets")
+ b.Put([]byte("foo"), []byte("baz"))
rwtxn.Rollback()
// Ensure that our original value is still set.