Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datastore: Create query with optional namespace #65

Merged
merged 1 commit into from
Jul 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions lib/datastore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,25 +336,20 @@ function Dataset(opts) {
/**
* Creates a query from the current dataset to query the specified
* kinds.
* @param {Array<String>} kinds A list of kinds to query.
* @return {Query}
*/
Dataset.prototype.createQuery = function(kinds) {
kinds = util.arrayize(kinds);
return new Query('', kinds);
};

/**
* Creates a query for collections identified with the specified
* namespace and kinds.
*
* Example usage:
* ds.createQueryNS('zoo', ['Lion', 'Chimp'])
* @param {string} ns Namespace to query entities from.
* @param {Array<object>} A list of kinds to query.
* ds.createQuery(['Lion', 'Chimp'])
* ds.createQuery('zoo', ['Lion', 'Chimp'])
*
* @param {string=} ns Optional namespace to query entities from.
* @param {Array<String>} kinds A list of kinds to query.
* @return {Query}
*/
Dataset.prototype.createQueryNS = function(ns, kinds) {
Dataset.prototype.createQuery = function(ns, kinds) {
if (!kinds) {
kinds = ns;
ns = '';
}
kinds = util.arrayize(kinds);
return new Query(ns, kinds);
};
Expand Down
4 changes: 2 additions & 2 deletions test/datastore.query.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ describe('Query', function() {
});

it('should use support custom namespaces', function(done) {
var q = ds.createQueryNS('ns', ['kind1']);
var q = ds.createQuery('ns', ['kind1']);
assert.equal(q.namespace, 'ns');
done();
});

it('should support querying multiple kinds', function(done) {
var q = ds.createQuery(['kind1', 'kind2']);
var qNS = ds.createQueryNS('ns', ['kind1', 'kind2']);
var qNS = ds.createQuery('ns', ['kind1', 'kind2']);

assert.strictEqual(q.namespace, '');
assert.equal(q.kinds[0], 'kind1');
Expand Down