mirror of
https://github.com/etcd-io/bbolt.git
synced 2025-05-31 11:42:30 +00:00
Add bucket retrieve example to README
Signed-off-by: Cenk Alti <cenkalti@gmail.com>
This commit is contained in:
parent
160cd29ec3
commit
6ec43f8da3
11
README.md
11
README.md
@ -296,6 +296,17 @@ db.Update(func(tx *bolt.Tx) error {
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can retrieve an existing bucket using the `Tx.Bucket()` function:
|
||||||
|
```go
|
||||||
|
db.Update(func(tx *bolt.Tx) error {
|
||||||
|
b := tx.Bucket([]byte("MyBucket"))
|
||||||
|
if b == nil {
|
||||||
|
return fmt.Errorf("bucket does not exist")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
You can also create a bucket only if it doesn't exist by using the
|
You can also create a bucket only if it doesn't exist by using the
|
||||||
`Tx.CreateBucketIfNotExists()` function. It's a common pattern to call this
|
`Tx.CreateBucketIfNotExists()` function. It's a common pattern to call this
|
||||||
function for all your top-level buckets after you open your database so you can
|
function for all your top-level buckets after you open your database so you can
|
||||||
|
Loading…
x
Reference in New Issue
Block a user