K
Kysely•2mo ago
Seifer

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?
Solution:
Kysely never "translates" anything.
Jump to solution
4 Replies
Solution
koskimas
koskimas•2mo ago
Kysely never "translates" anything.
koskimas
koskimas•2mo ago
Use fetch instead of limit
Igal
Igal•2mo ago
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#syntax
Seifer
SeiferOP•2mo ago
Thanks man, that clears up my doubts

Did you find this page helpful?