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: Avoid clearing offset when start cursor is set #93

Merged
merged 2 commits into from
Aug 5, 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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ Pagination allows you to set an offset, limit and starting cursor to a query.

~~~~ js
var q = ds.createQuery('Company')
.offset(100) // start from 101th result
.limit(10) // return only 10 results
.start(cursorToken); // continue to retrieve results from the given cursor.
.offset(100) // start from the 101th result after start cursor.
.limit(10) // return only 10 results
~~~~

#### Allocating IDs (ID generation)
Expand Down
2 changes: 1 addition & 1 deletion lib/datastore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ Transaction.prototype.runQuery = function(q, opt_callback) {
}
var nextQuery = null;
if (resp.batch.endCursor && resp.batch.endCursor != q.startVal) {
nextQuery = q.start(resp.batch.endCursor);
nextQuery = q.start(resp.batch.endCursor).offset(0);
}
opt_callback(null, entity.formatArray(resp.batch.entityResults), nextQuery);
});
Expand Down
1 change: 0 additions & 1 deletion lib/datastore/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ Query.prototype.select = function(fieldNames) {
Query.prototype.start = function(start) {
var q = util.extend(this, new Query());
q.startVal = start;
q.offsetVal = 0;
return q;
}

Expand Down
7 changes: 0 additions & 7 deletions test/datastore.query.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,6 @@ describe('Query', function() {
done();
});

it('should reset the offset to 0 when using start tokens', function(done) {
var q = ds.createQuery(['kind1']).offset(5);
q.start('startVal');
assert.strictEqual(q.offsetVal, 0);
done();
});

it('should be converted to a query proto successfully', function(done) {
var q = ds.createQuery(['Kind'])
.select(['name', 'count'])
Expand Down