Pagination
Hi everyone, I have a question. I'm working with a database in mssql and I'm creating a function to paginate the data in a table. For this I was doing something like the following: const person = await db
.selectFrom('person')
.selectAll()
.where('id', '=', '1')
.offset(0)
.limit(10)
.execute(), but I realized that in mssql you can't use the expression "LIMIT" but you have to use "FETCH NEXT", so my question is this: doesn't Kysely translate the queries depending on the dialect being used? if this is the case, shouldn't the limit() function be translated to "FETCH NEXT", if you're using a dialect where "LIMIT" is not supported?
4 Replies
Solution
Kysely never "translates" anything.
Use
fetch
instead of limit
Hey 👋
As @koskimas pointed out. One of Kysely's core design principles is What You See Is What You Get. What you invoke, is exactly what you should get in the compiled query.
For MSSQL, you must, according to spec, use a combination of
order by
, offset
and fetch
. https://learn.microsoft.com/en-us/sql/t-sql/queries/select-order-by-clause-transact-sql?view=sql-server-ver16#syntaxThanks man, that clears up my doubts