Skip to content

Commit

Permalink
fix(query-builder): respect 0 as limit (#2700)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliversalzburg committed Feb 2, 2022
1 parent 30cc69d commit 3f284ed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/knex/src/query/QueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ export class QueryBuilder<T extends AnyEntity<T> = AnyEntity> {
return qb.orderByRaw(queryOrder);
}
}, this._orderBy);
Utils.runIfNotEmpty(() => qb.limit(this._limit!), this._limit);
Utils.runIfNotEmpty(() => qb.limit(this._limit!), this._limit != null);
Utils.runIfNotEmpty(() => qb.offset(this._offset!), this._offset);
Utils.runIfNotEmpty(() => this.helper.appendOnConflictClause(this.type, this._onConflict!, qb), this._onConflict);

Expand Down
6 changes: 6 additions & 0 deletions tests/QueryBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2518,6 +2518,12 @@ describe('QueryBuilder', () => {
spy.mockRestore();
});

test('limit of 0 limits results to 0',()=>{
const expected = 'select `e0`.`id` from `book2` as `e0` limit 0';
const sql = orm.em.createQueryBuilder(Book2).select('id').limit(0).getFormattedQuery();
expect(sql).toBe(expected);
});

afterAll(async () => orm.close(true));

});

0 comments on commit 3f284ed

Please sign in to comment.