timshannon/bolthold

Add ability to get all keys for type

Closed this issue · 1 comments

muety commented

I'd like to have a convenient way to list (or query) all keys for a certain, bolthold-managed type.

You can already do this pretty easily:

var keys []int
err := store.ForEach(query, func(record *Item) error {
    keys = append(keys, record.Key)
    return nil
})

If I built a generic solution, the API would have to look something like this:

func (s *Store) Keys(keyType, dataType interface{}, query *Query) (int, error) {
...
}

where you'd have to pass in your keyType for the result and a separate datatype. And I'd have to reflect both types, which would be slower than just using the ForEach above. The ForEach method is really nice because I can find the proper datatype from the argument passed into the function, so it becomes both the selector for the Bucket, as well as the target for the result.