pedrorijo91
pedrorijo91

Reputation: 7865

how to get paginated select on slick + postgresql

In a postgresql database, with slick 3, what's the best way to have pagination?

Upvotes: 9

Views: 4784

Answers (1)

Paweł Jurczenko
Paweł Jurczenko

Reputation: 4471

You can use take and drop methods on TableQuery objects. They will be translated to limit and offset in the resulting SQL query:

val users: TableQuery[UsersTable] = UsersTable.query

val firstPartOfUsers  = users.drop(0).take(25).result
val secondPartOfUsers = users.drop(25).take(25).result

Those two actions will be translated to the following SQL queries:

select "name", "email", "id" from "users" limit 25 offset 0
select "name", "email", "id" from "users" limit 25 offset 25

Upvotes: 16

Related Questions