timshannon / bolthold

BoltHold is an embeddable NoSQL store for Go types built on BoltDB
MIT License
648 stars 46 forks source link

Index don't get properly updated #14

Closed HeavyHorst closed 7 years ago

HeavyHorst commented 7 years ago

When i change the value of an indexed field and search for the old value, i still get results.

package main

import (
    "fmt"
    "log"

    "github.com/timshannon/bolthold"
)

type Person struct {
    Name     string
    Division string `boltholdIndex:"Division"`
}

var p1 = Person{"Hermann", "Division1"}

func main() {
    store, err := bolthold.Open("hold.db", 0666, nil)
    if err != nil {
        log.Fatalln(err)
    }

    store.Insert(p1.Name, p1)

    p1.Division = "test123"
    store.Update(p1.Name, p1)

    var result []Person
    err = store.Find(&result, bolthold.Where("Division").Eq("Division1"))
    fmt.Println(result)
}

The result is:

go run test.go
[{Hermann test123}]
timshannon commented 7 years ago

Yep, confirmed. I'm working on a fix.

Thanks for the report.

timshannon commented 7 years ago

Fixed in the latest master. Thanks again for the catch.