GeezerVison is showing github.com — datastore: Filter a query on a key · Issue #73 · googleapis/google-cloud-node
datastore: Filter a query on a key #73DescriptionHi !
We're pretty much in a hurry for now, hoping we will find some pretty live support here, so I'm quoting your name with hope it will help (sorry for that) : @silvolu @pcostell @rakyll
First, we had trouble with using the json key in 0.0.6 so we got back to pem file with version 0.0.5. But this is not about this issue.
We want to filter according to a non-ancestor Key. We have tried several things.
The naive one :
var q = ds.createQuery('Plop').limit(5).filter('fooAccountKey =', ['Mykind', 1243567])
It didn't work (Array not supported).
We then tried a more complicated one, looking at https://github.com/GoogleCloudPlatform/gcloud-node/blob/master/test/datastore.entity.js#L295 :
var q = ds.createQuery('Plop').limit(5).filter('fooAccountKey =', {
partitionId: {
datasetId: 's-my-app',
namespace: ''
},
path: {
kind: 'Mykind',
id: '1243567'
}
});
We are currently trying with a more "raw" request, using your tests for some help, still we don't get yet how to run a raw request directly ; we tried raw request with ds.runQuery(query).execute(), but no luck yet, maybe our raw request is not good yet
Keep up the good job, we'll probably contribute by our own soon :) Activitysilvolu commented on Jul 31, 2014 @temsa are you trying to filter by key?
If so, var q = ds.createQuery('Plop').limit(5).filter('__key__ =', ['Mykind', 1243567]); should be what you're looking for. pcostell commented on Jul 31, 2014 silvolu commented on Jul 31, 2014 rakyll commented on Jul 31, 2014
It looks like this currently is not possible.
Yes, #39 needs to be resolved as well and keys are represented as plain arrays, we need an explicit type to be able to convert a plain object to Entity proto. If there is an embedded key, I don't know whether it's a plain array or a key. So we need some boxing for keys, the way we've done it for Integer and Double types. temsa commented on Jul 31, 2014 We finally found a temporary solution, I have not the code under the eyes, but using google datastore api for node.js documentation, the unit tests and the code itself, we could create a raw request by our own, using GQL to ease creation, then use ds.transaction.makeReq to send it with auth.
It's defintively not elegant, yet it works, and we could do what we had to in the very short timeframe we had (dumping some parts of the datastore according to some filters, including keys) thanks to this lib 👍
Thank you all for your quick answers :)
By the way, #39 is effectively important. Boxing is a way to do it, yet a more implicit way could be done using simply duck typing and/or variable arguments/arity : keys seems the only primitive that is composed of an infinite list of string / long pairs 👍
var q = ds.createQuery('Plop').limit(5).filter('myKey =', 'Mykind', 1243567) could totally work, var q = ds.createQuery('Plop').limit(5).filter('myKey =', 'Mykind', 1243567, 'MyAncestorKind', 123), too, etc.
Yet boxing can be sometime practical if not too verbose : var q = ds.createQuery('Plop').limit(5).filter('myKey =', Key('Mykind', 1243567)) would do the trick too. Note that supporting both API could be possible at the same time. rakyll commented on Jul 31, 2014
keys seems the only primitive that is composed of an infinite list of string / long pairs
We can't depend on that. Arbitrary entities can have list of string, long pairs as data. Boxing will not be verbose. Something similar to ds.key('Kind', 123) as your proposed. changed the title [-]How can we filter a query on a key[/-] [+]datastore: Filter a query on a key[/+] on Jul 31, 2014temsa commented on Jul 31, 2014
Arbitrary entities can have list of string
Yet they could be expressed as Arrays, while Keys could be expressed as vararg or ds.key.
Concerning ds.key, maybe ds.Key would be better, so you can do a var Key = ds.Key and use Key as you would have done in a GQL query. You could do it with ds.key too, yet it would seem less natural for a developer.
So, a ds.Key object would be fine for explicit boxing, with the constructor serving as a factory so Key(...) would be equivalent to new Key(...), so the boxing would still be light to write for the developer.
What do you think ? added this to the This milestone has been deleted milestone on Aug 5, 2014rakyll commented on Aug 8, 2014
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|