Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using badger as shown in readme does not work #154

Open
l0ngest opened this issue Sep 3, 2024 · 2 comments
Open

using badger as shown in readme does not work #154

l0ngest opened this issue Sep 3, 2024 · 2 comments

Comments

@l0ngest
Copy link

l0ngest commented Sep 3, 2024

Hi there, thanks in advance for your time. Looking at this part of the readme:

import (
  "log"
  "github.com/dgraph-io/badger/v4"
  c "github.com/ostafen/clover"
  badgerstore "github.com/ostafen/clover/v2/store/badger"
)

...

// by default, Bolt will be used internally
db, _ := c.Open("clover-db")

// use OpenWithStore() if you want to select a different storage backend
store, _ := badgerstore.Open(badger.DefaultOptions("").WithInMemory(true)) // opens a badger in memory database
db, _ := c.OpenWithStore(store)

defer db.Close() // remember to close the db when you have done

I have copy-pasted this exactly, but on this line:
store, _ := badgerstore.Open(badger.DefaultOptions("").WithInMemory(true)) // opens a badger in memory database

I get this error:
"Cannot use 'badger.DefaultOptions("").WithInMemory(true)' (type "github.com/dgraph-io/badger/v4".Options) as the type "github.com/dgraph-io/badger/v3".Options"

It appears that if I use badger v3 it works; however, given that the readme example uses badger v4 I spent a while thinking I've done something wrong. Is badger v4 not supported?

@ostafen
Copy link
Owner

ostafen commented Sep 3, 2024

Are you sure you are pulling the latest version?
Clover is using badger v4

@MaximeBellou
Copy link

MaximeBellou commented Oct 10, 2024

Hello,
I have the exact same issue.
With go version go1.22.1 darwin/arm64. I create a new project, make a go mod init .
I create a main.go file, and paste this code :

package main

import (
	"github.com/dgraph-io/badger/v4"
	c "github.com/ostafen/clover"
	badgerstore "github.com/ostafen/clover/v2/store/badger"
)

func main() {
	// use OpenWithStore() if you want to select a different storage backend
	store, _ := badgerstore.Open(badger.DefaultOptions("").WithInMemory(true)) // opens a badger in memory database
	db, _ := c.OpenWithStore(store)

	defer db.Close() // remember to close the db when you have done
}

I run go mod tidy and get this go.mod:

module new-project

go 1.22.1

require (
	github.com/dgraph-io/badger/v4 v4.3.1
	github.com/ostafen/clover v1.2.0
	github.com/ostafen/clover/v2 v2.0.0-alpha.3
)

require (
	github.com/cespare/xxhash v1.1.0 // indirect
	github.com/cespare/xxhash/v2 v2.3.0 // indirect
	github.com/dgraph-io/badger/v3 v3.2103.2 // indirect
	github.com/dgraph-io/ristretto v1.0.0 // indirect
	github.com/dustin/go-humanize v1.0.1 // indirect
	github.com/gogo/protobuf v1.3.2 // indirect
	github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
	github.com/golang/protobuf v1.5.4 // indirect
	github.com/golang/snappy v0.0.4 // indirect
	github.com/google/flatbuffers v24.3.25+incompatible // indirect
	github.com/klauspost/compress v1.17.10 // indirect
	github.com/pkg/errors v0.9.1 // indirect
	github.com/satori/go.uuid v1.2.0 // indirect
	go.opencensus.io v0.24.0 // indirect
	golang.org/x/net v0.29.0 // indirect
	golang.org/x/sys v0.25.0 // indirect
	google.golang.org/protobuf v1.33.0 // indirect
)

From this moment, I get this error : Cannot use 'badger.DefaultOptions("").WithInMemory(true)' (type "github.com/dgraph-io/badger/v4".Options) as the type "github.com/dgraph-io/badger/v3".Options

and Cannot resolve c.OpenWithStore

Changing the import c "github.com/ostafen/clover" into c "github.com/ostafen/clover/v2" resolves the "Cannot resolve c.OpenWithStore" error.

Changing the import "github.com/dgraph-io/badger/v4" into "github.com/dgraph-io/badger/v3" resolve the WithInMemory issue.

But continuing in the Readme file, if I try to use db.FindAll(c.NewQuery("todos")) , I get a Unresolved reference NewQuery error.
To solve this error, I have to import "github.com/ostafen/clover/v2/query" and use this code : docs, _ := db.FindAll(query.NewQuery("todos"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants