Skip to content

Instantly share code, notes, and snippets.

@piboistudios
Created May 30, 2018 18:55
Show Gist options
  • Save piboistudios/bb443b595a7a090caf4a831cd93a7fd1 to your computer and use it in GitHub Desktop.
Save piboistudios/bb443b595a7a090caf4a831cd93a7fd1 to your computer and use it in GitHub Desktop.
Google Cloud Datastore Filtered Query Generator
const keyfile = require('my-keyfile.json');
let config = {
credentials: keyfile
};
const Datastore = require('@google-cloud/datastore')(config);
let genFilteredQuery = query => {
let _query = Datastore.createQuery(query.kind !== null ? query.kind : '');
return query.filters.reduce((lastStatement, currentStatement, index) => {
return lastStatement
.filter.apply(_query, query.filters[index]);
}, _query);
}
/* QUERY OBJECT SCHEMA:
query: {
kind: "Task",
filters: [
[
"priority",
">",
"3"
],
[
"description",
"=",
"Greet everybody."
]
]
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment