tidwall / buntdb

BuntDB is an embeddable, in-memory key/value database for Go with custom indexing and geospatial support
MIT License
4.57k stars 289 forks source link

Case insensitive match #14

Closed angrz closed 8 years ago

angrz commented 8 years ago

Hi, is it possible to match key+"*" in case insensitive mode? Thanks

tidwall commented 8 years ago

Do you mean matching keys when adding to indexes?

This is not currently. Perhaps I could add an options to CreateIndex that allow for specifying case-insensitive pattern matching. Would something like this work?

opts := buntdb.IndexOptions{
        CaseInsensitiveKeyMatching: true,
}
buntdb.CreateIndexOptions("myindex", "user:*", &opts, buntdb.IndexString)
angrz commented 8 years ago

Exactly, that would be great

tidwall commented 8 years ago

I just pushed this feature to the master branch. It works as described above with the exception that the index must be created in a transaction:

db.Update(func(tx *buntdb.Tx) error{
        opts := buntdb.IndexOptions{
                CaseInsensitiveKeyMatching: true,
        }
        return tx.CreateIndexOptions("myindex", "user:*", &opts, buntdb.IndexString)
})