googleapis / googleapis/google-cloud-go
datastore: Export query struct fields
- Dominant language
- Go
- Stars
- 4.5k
- Forks
- 1.6k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 109
Description
**Is your feature request related to a problem? Please describe.**
I'm trying to use Redis to cache datastore entities and queries. The problem is that the `Query` struct does not export any of its fields (kind, ancestor, etc) so I have no way of generating a cache key from a provided query, other than using [hacky reflection techniques](https://stackoverflow.com/questions/42664837/how-to-access-unexported-struct-fields) or building a wrapper around it.
**Describe the solution you'd like**
Export fields that could be used to generate a redis key:
```
type Query struct {
Kind string
Ancestor *Key
Filter []filter
Order []order
Projection []string
distinct bool
distinctOn []string
keysOnly bool
eventual bool
Limit int32
offset int32
start []byte
end []byte
namespace string
trans *Transaction
err error
}
```
**Describe alternatives you've considered**
Current best alternative is to build a wrapper around Query so a way to uniquely id query can be captured or to use hacky reflection (which I don't want to do since a later version of datastore may break it).
As an example:
Given a `key datastore.Key` I can generate a redis key with `fmt.Sprintf("%s:%d", key.Kind, key.ID)`. With a query though... I have no way of uniquely fingerprinting it so it's hard to map a query to cached results of that query. If you don't want to expose those fields, maybe a `Fingerprint()` method would be fine as well.
i.e. if you had a `q datastore.Query` you could call `q.Fingerprint()` which returns a string that uniquely identifies it (could be as simple as `kind:ancestor:filters:order:projection:limit`, for example `User:::Last Name::100`)
Contributor guide
Assessment
This issue has not been assessed yet.