1

Since the new version of BadgerDB, many of the old tutorials I've been looking at don't work. So I'm following the documentation, specifically with key loaders: https://godoc.org/github.com/dgraph-io/badger#KVLoader

I've tried making a simple mapping in Go but keep getting errors.

My code is simply

  db, err := badger.Open(badger.DefaultOptions("./tmp"))
  if err != nil {
      log.Fatal(err)
  }

  defer db.Close()
  // Your code here…

  var env = map[string]int{
     "key0": 10,
     "key1": 398,
  }

  kv := db.NewKVLoader(5)
  kv.Set(env)

It keeps saying cannot use env (type map[string]int) as type *pb.KV in argument to kv.Set. Should I be using it this way? How can I write my key-value pair?

Luke Zhang
  • 343
  • 1
  • 4
  • 14
  • wdym write my KV pair? Why cant you use a regular transaction err := db.Update(func(txn *badger.Txn) error { err := txn.Set([]byte("answer-key"), []byte("42-value")) return err }) – Asad Awadia May 03 '23 at 23:59
  • https://dgraph.io/docs/badger/get-started/#using-key-value-pairs – Asad Awadia May 03 '23 at 23:59

0 Answers0