select from a table with a list of case class values in where clause

53 views Asked by At

I have a val employees: List[Employee] and I need to query a table in a performant way, around these lines:

employees.foreach(employee => Select etable.id from employees_salary etable 
where etable.id == employee.id and etable.salary < 50000)

I want to filter val employees who have salary < 50000 but I want to fire one single query to database using squeryl. As I am still learning squeryl, don't know how to do this. Your help is much appreciated. Thanks in advance for help

1

There are 1 answers

0
jcern On

Assuming employees is your table mapping, ie: org.squeryl.Table[Employee], then you would just need to use squeryl's query syntax. In your case, ,it would look something like this:

from(employees)(etable => 
  where(etable.salary lt 50000) 
  select(etable)
)

You can call toList on the above if you need the resultset as a List[Employee]