timshannon / badgerhold

BadgerHold is an embeddable NoSQL store for querying Go types built on Badger
MIT License
515 stars 52 forks source link

Issue with basic example #15

Closed davedbase closed 4 years ago

davedbase commented 4 years ago

Hi Tim, great work on this project. I attempted running an example and got an error:

type Item struct {
    Name    string
    Created time.Time
}
store, err := badgerhold.Open("example", 0666, nil)
if err != nil {
    fmt.Println(err)
}
err = store.Insert("key", &Item{
    Name:    "Test Name",
    Created: time.Now(),
})

The resulting error:

../../pkg/mod/github.com/timshannon/badgerhold@v0.0.0-20190813142441-2228c3d8c084/store.go:48:41: cannot call non-function badger.DefaultOptions (type badger.Options)

Not sure if I did something incorrectly (doesn't look like it). Any ideas?

timshannon commented 4 years ago

Try running go get -u and trying again.

Check out #14

davedbase commented 4 years ago

Ah. K. I just looked at example_test.go and the Open params are different than stated at the bottom of the README. I just updated my example and getting this now:

    type Item struct {
        Name    string
        Created time.Time
    }
    options := badgerhold.DefaultOptions
    options.Dir = "test"
    options.ValueDir = "testval"
    store, err := badgerhold.Open(options)
    if err != nil {
        fmt.Println(err)
    }
    err = store.Insert("key", struct {
        Name    string
        Created time.Time
    }{
        Name:    "Test Name",
        Created: time.Now(),
    })

Error:

goroutine 1 [running]:
github.com/timshannon/badgerhold.newStorer(0x4f83100, 0xc0000c35f0, 0xa, 0x0)
    /Users/daviddibiase/go/pkg/mod/github.com/timshannon/badgerhold@v0.0.0-20190813142441-2228c3d8c084/store.go:145 +0x666
github.com/timshannon/badgerhold.(*Store).TxInsert(0xc00560c0e0, 0xc00002e080, 0x4f36840, 0x50c9f20, 0x4f83100, 0xc0000c35f0, 0xb, 0xc00002e080)
    /Users/daviddibiase/go/pkg/mod/github.com/timshannon/badgerhold@v0.0.0-20190813142441-2228c3d8c084/put.go:47 +0x50
github.com/timshannon/badgerhold.(*Store).Insert.func1(0xc00002e080, 0x4f80001, 0xc00002e080)
    /Users/daviddibiase/go/pkg/mod/github.com/timshannon/badgerhold@v0.0.0-20190813142441-2228c3d8c084/put.go:41 +0x58
github.com/dgraph-io/badger.(*DB).Update(0xc000254000, 0xc00563bcc8, 0x0, 0x0)
    /Users/daviddibiase/go/pkg/mod/github.com/dgraph-io/badger@v1.6.0/txn.go:696 +0x94
github.com/timshannon/badgerhold.(*Store).Insert(0xc00560c0e0, 0x4f36840, 0x50c9f20, 0x4f83100, 0xc0000c35f0, 0x5011759, 0xa)
    /Users/daviddibiase/go/pkg/mod/github.com/timshannon/badgerhold@v0.0.0-20190813142441-2228c3d8c084/put.go:40 +0x8a
main.main()
    /Users/daviddibiase/go/src/massive/main.go:28 +0x246
exit status 2
davedbase commented 4 years ago

Ignore that previous post, I tested it in haste and made a mistake. Thanks for the quick help.