Skip to content

Commit

Permalink
Merge pull request #604 from ryanseys/select-single-prop
Browse files Browse the repository at this point in the history
datastore: add select support for single property
  • Loading branch information
ryanseys committed May 19, 2015
2 parents 67f795b + b603e80 commit 420cb84
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/datastore/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
6 changes: 6 additions & 0 deletions test/datastore/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down

0 comments on commit 420cb84

Please sign in to comment.