aboutsummaryrefslogtreecommitdiff
path: root/example_test.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-03-08 20:25:37 -0700
committerBen Johnson <benbjohnson@yahoo.com>2014-03-08 20:40:48 -0700
commitc551e45a4722f58dc4c19f9d1b80b0b8db3ad039 (patch)
tree93ac43914f9cd20c8eea13f18105e55026a7ea8d /example_test.go
parentRename Transaction to Tx. (diff)
downloaddedo-c551e45a4722f58dc4c19f9d1b80b0b8db3ad039.tar.gz
dedo-c551e45a4722f58dc4c19f9d1b80b0b8db3ad039.tar.xz
Consolidate Tx and RWTx.
Diffstat (limited to 'example_test.go')
-rw-r--r--example_test.go28
1 files changed, 14 insertions, 14 deletions
diff --git a/example_test.go b/example_test.go
index 82db552..0185bb1 100644
--- a/example_test.go
+++ b/example_test.go
@@ -67,7 +67,7 @@ func ExampleDB_Do() {
defer db.Close()
// Execute several commands within a write transaction.
- err := db.Do(func(t *RWTx) error {
+ err := db.Do(func(t *Tx) error {
if err := t.CreateBucket("widgets"); err != nil {
return err
}
@@ -134,30 +134,30 @@ func ExampleDB_ForEach() {
// A liger is awesome.
}
-func ExampleRWTx() {
+func ExampleTx() {
// Open the database.
var db DB
- db.Open("/tmp/bolt/rwtx.db", 0666)
+ db.Open("/tmp/bolt/tx.db", 0666)
defer db.Close()
// Create a bucket.
db.CreateBucket("widgets")
// Create several keys in a transaction.
- rwtxn, _ := db.RWTx()
- b := rwtxn.Bucket("widgets")
+ tx, _ := db.RWTx()
+ b := tx.Bucket("widgets")
b.Put([]byte("john"), []byte("blue"))
b.Put([]byte("abby"), []byte("red"))
b.Put([]byte("zephyr"), []byte("purple"))
- rwtxn.Commit()
+ tx.Commit()
// Iterate over the values in sorted key order.
- txn, _ := db.Tx()
- c := txn.Bucket("widgets").Cursor()
+ tx, _ = db.Tx()
+ c := tx.Bucket("widgets").Cursor()
for k, v := c.First(); k != nil; k, v = c.Next() {
fmt.Printf("%s likes %s\n", string(k), string(v))
}
- txn.Close()
+ tx.Rollback()
// Output:
// abby likes red
@@ -165,10 +165,10 @@ func ExampleRWTx() {
// zephyr likes purple
}
-func ExampleRWTx_rollback() {
+func ExampleTx_rollback() {
// Open the database.
var db DB
- db.Open("/tmp/bolt/rwtx_rollback.db", 0666)
+ db.Open("/tmp/bolt/tx_rollback.db", 0666)
defer db.Close()
// Create a bucket.
@@ -178,10 +178,10 @@ func ExampleRWTx_rollback() {
db.Put("widgets", []byte("foo"), []byte("bar"))
// Update the key but rollback the transaction so it never saves.
- rwtxn, _ := db.RWTx()
- b := rwtxn.Bucket("widgets")
+ tx, _ := db.RWTx()
+ b := tx.Bucket("widgets")
b.Put([]byte("foo"), []byte("baz"))
- rwtxn.Rollback()
+ tx.Rollback()
// Ensure that our original value is still set.
value, _ := db.Get("widgets", []byte("foo"))