aboutsummaryrefslogtreecommitdiff
path: root/example_test.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-02-16 13:51:35 -0700
committerBen Johnson <benbjohnson@yahoo.com>2014-02-16 13:59:07 -0700
commitb22480fd32daa1c3f6542f4158916651610c3d6e (patch)
treefbdf8f185404a1eaa92c927bf0fce63126b69f5f /example_test.go
parentAdd CreateBucketIfNotExists(). (diff)
downloaddedo-b22480fd32daa1c3f6542f4158916651610c3d6e.tar.gz
dedo-b22480fd32daa1c3f6542f4158916651610c3d6e.tar.xz
Add Transaction.ForEach().
Diffstat (limited to 'example_test.go')
-rw-r--r--example_test.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/example_test.go b/example_test.go
index 655e283..542109c 100644
--- a/example_test.go
+++ b/example_test.go
@@ -87,6 +87,30 @@ func ExampleDB_Do() {
// The value of 'foo' is: bar
}
+func ExampleDB_ForEach() {
+ // Open the database.
+ var db DB
+ db.Open("/tmp/bolt/db_foreach.db", 0666)
+ defer db.Close()
+
+ // Insert data into a bucket.
+ db.CreateBucket("animals")
+ db.Put("animals", []byte("dog"), []byte("fun"))
+ db.Put("animals", []byte("cat"), []byte("lame"))
+ db.Put("animals", []byte("liger"), []byte("awesome"))
+
+ // Iterate over items in sorted key order.
+ db.ForEach("animals", func(k, v []byte) error {
+ fmt.Printf("A %s is %s.\n", string(k), string(v))
+ return nil
+ })
+
+ // Output:
+ // A cat is lame.
+ // A dog is fun.
+ // A liger is awesome.
+}
+
func ExampleRWTransaction() {
// Open the database.
var db DB