From b603e802adb6d7636f0a78613ad4aec7abf2b2ad Mon Sep 17 00:00:00 2001 From: Ryan Seys Date: Sun, 17 May 2015 14:21:55 -0400 Subject: [PATCH] datastore: add select support for single property --- lib/datastore/query.js | 8 ++++++-- test/datastore/query.js | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/datastore/query.js b/lib/datastore/query.js index 40939cde3a5..8f6a968f116 100644 --- a/lib/datastore/query.js +++ b/lib/datastore/query.js @@ -180,16 +180,20 @@ Query.prototype.groupBy = function(fieldNames) { * * *[More information on projection queries](http://goo.gl/EfsrJl).* * - * @param {array} fieldNames - Properties to return from the matched entities. + * @param {string|string[]} fieldNames - Properties to return from the matched + * entities. * @return {module:datastore/query} * * @example + * // Only retrieve the name property. + * var selectQuery = companyQuery.select('name'); + * * // Only retrieve the name and size properties. * var selectQuery = companyQuery.select(['name', 'size']); */ Query.prototype.select = function(fieldNames) { var query = extend(new Query(), this); - query.selectVal = fieldNames; + query.selectVal = util.arrayize(fieldNames); return query; }; diff --git a/test/datastore/query.js b/test/datastore/query.js index ab8883978d3..db26f5f35fd 100644 --- a/test/datastore/query.js +++ b/test/datastore/query.js @@ -63,6 +63,12 @@ describe('Query', function() { assert.equal(query.selectVal[1], 'title'); }); + it('should support single field selection by field name', function() { + var query = new Query(['kind1']) + .select('name'); + assert.equal(query.selectVal[0], 'name'); + }); + it('should support ancestor filtering', function() { var query = new Query(['kind1']) .hasAncestor(['kind2', 123]);