From 2618039c28b72c14166e893cf5085b4787aeda0c Mon Sep 17 00:00:00 2001 From: ErikKalkoken Date: Sun, 25 Aug 2024 17:29:16 +0200 Subject: [PATCH] Add info on how to list existing buckets Signed-off-by: ErikKalkoken --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index c4ee84875..04cfe7254 100644 --- a/README.md +++ b/README.md @@ -315,6 +315,17 @@ guarantee that they exist for future transactions. To delete a bucket, simply call the `Tx.DeleteBucket()` function. +You can also iterate over all existing buckets with `Tx.forEach()`: + +```go +db.View(func(tx *bolt.Tx) error { + tx.ForEach(func(name []byte, b *bolt.Bucket) error { + fmt.Println(string(name)) + return nil + }) + return nil +}) +``` ### Using key/value pairs