timshannon / badgerhold

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

Custom index name error #71

Closed Ale1ster closed 3 years ago

Ale1ster commented 3 years ago

When a struct has an index defined on a field whose name does not match the field name, the specified index name is not respected:

type Person struct {
    Name string
    Division string `badgerholdIndex:"IdxDivision"`
}

In the above struct, the query

badgerhold.Where("Division").Eq("sales").Index("IdxDivision")

fails with the error The index IdxDivision does not exist, while the query

badgerhold.Where("Division").Eq("sales").Index("Division")

is executed successfully.

This behaviour is observed against tag v1.0.0 (commit hash 8addb9d), but the same should be observed in v3.0.0 (2b6764d) tag as well.

timshannon commented 3 years ago

Originally all the query methods referenced field names, but it clearly states indexName in my documentation 🤦‍♂️, that's a complete oversight.

Thanks for the report. I'll fix this on the V3 branch, as well as new V4 version on master that will contain some other backward incompatible changes.

timshannon commented 3 years ago

This should be good now with both v3 and v4 (master).

Thanks