Skip to content

B4a 528 - Adds limit = 0 as a valid parameter for queries #1

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

Closed
wants to merge 3 commits into from
Closed
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
29 changes: 29 additions & 0 deletions spec/RestQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,33 @@ describe('rest query', () => {
});
});

it('query with limit = 0', (done) => {
rest.create(config, nobody, 'TestObject', {foo: 'baz'}
).then(() => {
return rest.create(config, nobody,
'TestObject', {foo: 'qux'});
}).then(() => {
return rest.find(config, nobody,
'TestObject', {}, {limit: 0});
}).then((response) => {
expect(response.results.length).toEqual(0);
done();
});
});

it('query with limit = 0 and count = 1', (done) => {
rest.create(config, nobody, 'TestObject', {foo: 'baz'}
).then(() => {
return rest.create(config, nobody,
'TestObject', {foo: 'qux'});
}).then(() => {
return rest.find(config, nobody,
'TestObject', {}, {limit: 0, count: 1});
}).then((response) => {
expect(response.results.length).toEqual(0);
expect(response.count).toEqual(2);
done();
});
});

});
4 changes: 4 additions & 0 deletions src/RestQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ RestQuery.prototype.replaceDontSelect = function() {
// Returns a promise for whether it was successful.
// Populates this.response with an object that only has 'results'.
RestQuery.prototype.runFind = function() {
if (this.findOptions.limit === 0) {
this.response = {results: []};
return Promise.resolve();
}
return this.config.database.find(
this.className, this.restWhere, this.findOptions).then((results) => {
if (this.className === '_User') {
Expand Down
2 changes: 1 addition & 1 deletion src/Routers/ClassesRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class ClassesRouter extends PromiseRouter {
if (body.skip) {
options.skip = Number(body.skip);
}
if (body.limit) {
if (body.limit || body.limit === 0) {
options.limit = Number(body.limit);
} else {
options.limit = Number(100);
Expand Down