aboutsummaryrefslogtreecommitdiff
path: root/example_test.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-02-16 15:43:35 -0700
committerBen Johnson <benbjohnson@yahoo.com>2014-02-16 15:43:35 -0700
commit459b8eb4ab16516974ff616196e4a2593ecbb7b7 (patch)
tree67cb8ddbbde55b26db5fb3a7463cd181e41be465 /example_test.go
parentMerge pull request #36 from benbjohnson/for-each (diff)
downloaddedo-459b8eb4ab16516974ff616196e4a2593ecbb7b7.tar.gz
dedo-459b8eb4ab16516974ff616196e4a2593ecbb7b7.tar.xz
Read-only transactional block.
Diffstat (limited to 'example_test.go')
-rw-r--r--example_test.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/example_test.go b/example_test.go
index 542109c..8747f94 100644
--- a/example_test.go
+++ b/example_test.go
@@ -87,6 +87,28 @@ func ExampleDB_Do() {
// The value of 'foo' is: bar
}
+func ExampleDB_With() {
+ // Open the database.
+ var db DB
+ db.Open("/tmp/bolt/db_foreach.db", 0666)
+ defer db.Close()
+
+ // Insert data into a bucket.
+ db.CreateBucket("people")
+ db.Put("people", []byte("john"), []byte("doe"))
+ db.Put("people", []byte("susy"), []byte("que"))
+
+ // Access data from within a read-only transactional block.
+ db.With(func(t *Transaction) error {
+ v, _ := t.Get("people", []byte("john"))
+ fmt.Printf("John's last name is %s.\n", string(v))
+ return nil
+ })
+
+ // Output:
+ // John's last name is doe.
+}
+
func ExampleDB_ForEach() {
// Open the database.
var db DB