diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-02-16 15:43:35 -0700 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-02-16 15:43:35 -0700 |
commit | 459b8eb4ab16516974ff616196e4a2593ecbb7b7 (patch) | |
tree | 67cb8ddbbde55b26db5fb3a7463cd181e41be465 /example_test.go | |
parent | Merge pull request #36 from benbjohnson/for-each (diff) | |
download | dedo-459b8eb4ab16516974ff616196e4a2593ecbb7b7.tar.gz dedo-459b8eb4ab16516974ff616196e4a2593ecbb7b7.tar.xz |
Read-only transactional block.
Diffstat (limited to 'example_test.go')
-rw-r--r-- | example_test.go | 22 |
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 |