aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2016-01-11 18:59:16 -0800
committerBen Johnson <benbjohnson@yahoo.com>2016-01-11 18:59:16 -0800
commit4030e7fbc16465ec02334c93396b57629438096e (patch)
treed0e75cefa4c8764c45a80a4ad2c338e7be6c1f71
parentMerge pull request #478 from TrevorSStone/master (diff)
parentAdd bucket check to db.View in readme.md (diff)
downloaddedo-4030e7fbc16465ec02334c93396b57629438096e.tar.gz
dedo-4030e7fbc16465ec02334c93396b57629438096e.tar.xz
Merge pull request #484 from etelej/master
Add bucket check to db.View in readme.md
-rw-r--r--README.md7
1 files changed, 6 insertions, 1 deletions
diff --git a/README.md b/README.md
index a582e86..c620801 100644
--- a/README.md
+++ b/README.md
@@ -349,7 +349,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() {
@@ -390,6 +392,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")
@@ -409,7 +412,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.
@@ -433,7 +436,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