From 459b8eb4ab16516974ff616196e4a2593ecbb7b7 Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Sun, 16 Feb 2014 15:43:35 -0700 Subject: Read-only transactional block. --- example_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'example_test.go') 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 -- cgit v1.2.3