konfachcloud-discord-bot/cmd/dbviewer/main.go

36 lines
578 B
Go
Raw Permalink Normal View History

2024-06-27 13:45:32 +00:00
package main
import (
"fmt"
"github.com/dgraph-io/badger/v4"
)
func main() {
opts := badger.DefaultOptions("./db/hash")
db, err := badger.Open(opts)
if err != nil {
panic(err)
}
defer db.Close()
err = db.View(func(txn *badger.Txn) error {
it := txn.NewIterator(badger.DefaultIteratorOptions)
defer it.Close()
for it.Rewind(); it.Valid(); it.Next() {
item := it.Item()
val, err := item.ValueCopy(nil)
if err != nil {
return err
}
fmt.Println(string(item.Key()) + " " + string(val))
}
return nil
})
if err != nil {
panic(err)
}
}