aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorPeter Etelej <peter@etelej.com>2016-01-09 09:34:55 +0300
committerPeter Etelej <peter@etelej.com>2016-01-12 05:28:15 +0300
commit769f43bec3c8ad7b4870c1f81509f15cbf5c1b08 (patch)
treee114d61a87f3fda8345caac6b1e13d76b933ccc2 /README.md
parentMerge pull request #479 from azazeal/master (diff)
downloaddedo-769f43bec3c8ad7b4870c1f81509f15cbf5c1b08.tar.gz
dedo-769f43bec3c8ad7b4870c1f81509f15cbf5c1b08.tar.xz
Add bucket check to db.View in readme.md
Add 'Assume bucket exists and has keys' comments on db.View calls accessing bucket keys in examples of db.View in readme.md code examples. Fixes #484
Diffstat (limited to 'README.md')
-rw-r--r--README.md7
1 files changed, 6 insertions, 1 deletions
diff --git a/README.md b/README.md
index cc968ce..7b098f1 100644
--- a/README.md
+++ b/README.md
@@ -348,7 +348,9 @@ iteration over these keys extremely fast. To iterate over keys we'll use a
```go
db.View(func(tx *bolt.Tx) error {
+ // Assume bucket exists and has keys
b := tx.Bucket([]byte("MyBucket"))
+
c := b.Cursor()
for k, v := c.First(); k != nil; k, v = c.Next() {
@@ -389,6 +391,7 @@ To iterate over a key prefix, you can combine `Seek()` and `bytes.HasPrefix()`:
```go
db.View(func(tx *bolt.Tx) error {
+ // Assume bucket exists and has keys
c := tx.Bucket([]byte("MyBucket")).Cursor()
prefix := []byte("1234")
@@ -408,7 +411,7 @@ date range like this:
```go
db.View(func(tx *bolt.Tx) error {
- // Assume our events bucket has RFC3339 encoded time keys.
+ // Assume our events bucket exists and has RFC3339 encoded time keys.
c := tx.Bucket([]byte("Events")).Cursor()
// Our time range spans the 90's decade.
@@ -432,7 +435,9 @@ all the keys in a bucket:
```go
db.View(func(tx *bolt.Tx) error {
+ // Assume bucket exists and has keys
b := tx.Bucket([]byte("MyBucket"))
+
b.ForEach(func(k, v []byte) error {
fmt.Printf("key=%s, value=%s\n", k, v)
return nil