Skip to content

Commit

Permalink
fix(Limit): use a parameter for limit number
Browse files Browse the repository at this point in the history
BREAKING CHANGE: A string expression as the limit number is no longer accepted. The argument must be
a number.
  • Loading branch information
jamesfer committed Jun 11, 2019
1 parent ea501ff commit 025c873
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/clauses/limit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ describe('Limit', () => {
describe('#build', () => {
it('should add a produce a limit clause', () => {
const query = new Limit(10);
expect(query.build()).to.equal('LIMIT 10');
expect(query.build()).to.equal('LIMIT $limitCount');
expect(query.getParams()).to.eql({ limitCount: 10 });
});

it('should accept a string param', () => {
// TODO re-add in 4.0
it.skip('should accept a string param', () => {
const query = new Limit('toInteger(3 * 4)');
expect(query.build()).to.equal('LIMIT toInteger(3 * 4)');
});
Expand Down
6 changes: 5 additions & 1 deletion src/clauses/limit.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Clause } from '../clause';
import { Parameter } from '../parameter-bag';

export class Limit extends Clause {
protected amountParam: Parameter;

constructor(public amount: number | string) {
super();
this.amountParam = this.addParam(amount, 'limitCount');
}

build() {
return `LIMIT ${this.amount}`;
return `LIMIT ${this.amountParam}`;
}
}

0 comments on commit 025c873

Please sign in to comment.