Search code examples
selectsqueryl

Squeryl select top


I would like to do something like the following but using Squeryl:

select top 10 * from table where conditionA = a

so far I can only get to: table.where(x => x.conditionA = a).head

The problem with this is the db call gets all the records that meets the condition from the db, while I only need the top one.

I cannot find another way to do the select top in Squeryl which only brings the necessary amount of records back from db.

Anyone know how to do this?

Thanks.


Solution

  • Squeryl has a method called page which you can use to specify a LIMIT and OFFSET for the query.

    In your example; table.where(x => x.conditionA === a).page(0, 10).toList should achieve what you are looking to do.