Closed ivanjaros closed 3 years ago
There is a comparer interface that you can define on your type if you want it to compare values differently from Go standard.
There are examples in the tests (https://github.com/timshannon/badgerhold/blob/master/compare_test.go):
type CItemTest struct {
Inner ItemTest
}
func (i *ItemTest) Compare(other interface{}) (int, error) {
if other, ok := other.(ItemTest); ok {
if i.ID == other.ID {
return 0, nil
}
if i.ID < other.ID {
return -1, nil
}
return 1, nil
}
return 0, &badgerhold.ErrTypeMismatch{Value: i, Other: other}
}
i dont get it. dont you have indices stored as part of keys with values pointing to object ids? this example looks like you are loading entire objects and comparing them as a whole...where does the index come into this?
Ah. Sorry I misunderstood. If you're talking about index values specifically, then you can implement the Storer
interface.
https://github.com/timshannon/badgerhold/blob/master/store.go#L101
I have some indices but I want them to be case-insensitive. So instead of having to define two fields - one for original value and the other for index value, it would be good if there would be tag support for something like 'lowercase' or 'uppercase' or something like that. This is especially useful for e-mail addresses where the case can vary but I always want to index it as lower-cased value. Same as things like handles/slugs like for twitter or github user names.