35 lines
578 B
Go
35 lines
578 B
Go
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)
|
|
}
|
|
}
|