From d61ec2f2e66e15dc820af3069ba38ae8bfe9a21c Mon Sep 17 00:00:00 2001 From: Burcu Dogan Date: Tue, 29 Jul 2014 14:22:06 -0700 Subject: [PATCH] datastore: Create query with optional namespace. --- lib/datastore/index.js | 25 ++++++++++--------------- test/datastore.query.js | 4 ++-- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/lib/datastore/index.js b/lib/datastore/index.js index 74a434636b2..cde919ac085 100644 --- a/lib/datastore/index.js +++ b/lib/datastore/index.js @@ -336,25 +336,20 @@ function Dataset(opts) { /** * Creates a query from the current dataset to query the specified * kinds. - * @param {Array} 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} 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} 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); }; diff --git a/test/datastore.query.js b/test/datastore.query.js index 2652cc8ba49..1b72f33c481 100644 --- a/test/datastore.query.js +++ b/test/datastore.query.js @@ -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');