Skip to content

Commit

Permalink
feat: expands limit in select accepting null value (kysely-org#1347)
Browse files Browse the repository at this point in the history
* feat: expands limit in select accepting null value

* explain in jsdocs, move test case.

Co-authored-by: Alessio Napolitano <121714208+alenap93@users.noreply.github.com>

---------

Co-authored-by: igalklebanov <igalklebanov@gmail.com>
  • Loading branch information
alenap93 and igalklebanov committed Feb 18, 2025
1 parent 989bac2 commit 6467b77
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/query-builder/select-query-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,9 @@ export interface SelectQueryBuilder<DB, TB extends keyof DB, O>
/**
* Adds a limit clause to the query.
*
* Passing a `null` value is only supported by some dialects like PostgreSQL,
* and will result in a no-op limit clause.
*
* ### Examples
*
* Select the first 10 rows of the result:
Expand Down Expand Up @@ -1160,7 +1163,7 @@ export interface SelectQueryBuilder<DB, TB extends keyof DB, O>
* ```
*/
limit(
limit: ValueExpression<DB, TB, number | bigint>,
limit: ValueExpression<DB, TB, number | bigint | null>,
): SelectQueryBuilder<DB, TB, O>

/**
Expand Down Expand Up @@ -2417,7 +2420,7 @@ class SelectQueryBuilderImpl<DB, TB extends keyof DB, O>
}

limit(
limit: ValueExpression<DB, TB, number | bigint>,
limit: ValueExpression<DB, TB, number | bigint | null>,
): SelectQueryBuilder<DB, TB, O> {
return new SelectQueryBuilderImpl({
...this.#props,
Expand Down
22 changes: 22 additions & 0 deletions test/node/src/select.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,28 @@ for (const dialect of DIALECTS) {
})
}

if (dialect === 'postgres') {
it('should create a select query with limit null', async () => {
const query = ctx.db
.selectFrom('person')
.select('first_name')
.limit(null)

testSql(query, dialect, {
postgres: {
sql: `select "first_name" from "person" limit $1`,
parameters: [null],
},
mysql: NOT_SUPPORTED,
mssql: NOT_SUPPORTED,
sqlite: NOT_SUPPORTED,
})

const result = await query.execute()
expect(result).to.have.length(3)
})
}

it('should create a select statement without a `from` clause', async () => {
const query = ctx.db.selectNoFrom((eb) => [
eb
Expand Down

0 comments on commit 6467b77

Please sign in to comment.