Created
May 30, 2018 18:55
-
-
Save piboistudios/bb443b595a7a090caf4a831cd93a7fd1 to your computer and use it in GitHub Desktop.
Google Cloud Datastore Filtered Query Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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