Fixed UsergridResponse.loadNextPage and UsergridQuery._ql when no query and sort are
Project: http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/repo Commit: http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/commit/2f3c3fe5 Tree: http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/tree/2f3c3fe5 Diff: http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/diff/2f3c3fe5 Branch: refs/heads/master Commit: 2f3c3fe55dda9957b4662d6cb076aba0b1494159 Parents: 05758e0 Author: Robert Walsh <[email protected]> Authored: Mon Oct 10 11:32:42 2016 -0500 Committer: Robert Walsh <[email protected]> Committed: Mon Oct 10 11:32:42 2016 -0500 ---------------------------------------------------------------------- lib/query.js | 7 +++++-- lib/response.js | 7 ++++--- tests/lib/query.test.js | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/2f3c3fe5/lib/query.js ---------------------------------------------------------------------- diff --git a/lib/query.js b/lib/query.js index a1d46b4..a819108 100644 --- a/lib/query.js +++ b/lib/query.js @@ -104,11 +104,14 @@ var UsergridQuery = function(type) { // public accessors Object.defineProperty(self, '_ql', { get: function() { + var ql = 'select * ' if (queryString !== undefined) { - return queryString + ql = queryString } else { - return (query.length > 0 || sort !== undefined) ? util.format('select * where %s%s', query || '', sort || '') : "" + ql += ((query.length > 0) ? 'where ' + (query || '') : '') + ql += ((sort !== undefined) ? sort : '') } + return ql } }) http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/2f3c3fe5/lib/response.js ---------------------------------------------------------------------- diff --git a/lib/response.js b/lib/response.js index 3cd21e1..fade45c 100644 --- a/lib/response.js +++ b/lib/response.js @@ -63,9 +63,10 @@ UsergridResponse.prototype = { callback() } var client = helpers.client.validate(args) - var type = _.last(ok(this).getIfExists('metadata.path').split('/')) - var limit = _.first(ok(this).getIfExists('metadata.params.limit')) - var query = new UsergridQuery(type).cursor(this.metadata.cursor).limit(limit) + var type = _.last(_.get(this,'metadata.path').split('/')) + var limit = _.first(_.get(this,'metadata.params.limit')) + var ql = _.first(_.get(this,'metadata.params.ql')) + var query = new UsergridQuery(type).fromString(ql).cursor(this.metadata.cursor).limit(limit) return client.GET(query, callback) } } http://git-wip-us.apache.org/repos/asf/usergrid-nodejs/blob/2f3c3fe5/tests/lib/query.test.js ---------------------------------------------------------------------- diff --git a/tests/lib/query.test.js b/tests/lib/query.test.js index d9ecd41..7ec9cb4 100644 --- a/tests/lib/query.test.js +++ b/tests/lib/query.test.js @@ -33,9 +33,9 @@ describe('_limit', function() { }) describe('_ql', function() { - it('should be an empty string if query or sort are empty or underfined', function() { + it('should select * if query or sort are empty or underfined', function() { var query = new UsergridQuery('cats') - query.should.have.property('_ql').equal("") + query.should.have.property('_ql').equal('select * ') }) it('should support complex builder pattern syntax (chained constructor methods)', function() {
