Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

implicit value for slick.jdbc.SetParameter[List[Int]]

Tags:

scala

slick

I have a raw slick query backed by PostgreSQL. I want to run a query like this: select something from my_table where action in (1,2,3) . Note that action is an integer field in my_table

I'm getting a compilation error in my method below:

could not find implicit value for parameter e: slick.jdbc.SetParameter[List[Int]]

def myMethod(actions: List[Int]]) {
 sql"""select something from my_table 
        where action in (${actions})""".as[MyType]
}

Question

How can I explicitly set the List[Int] parameter so that I can successfully run the in query?

like image 726
Anthony Avatar asked Oct 17 '25 01:10

Anthony


2 Answers

Try

def myMethod(actions: List[Int]) =
  sql"""select something from my_table
        where action in #${actions.mkString("(", ",", ")")}""".as[MyType]

http://slick.lightbend.com/doc/3.3.0/sql.html#splicing-literal-values

https://www.w3schools.com/sql/sql_in.asp

like image 125
Dmytro Mitin Avatar answered Oct 20 '25 04:10

Dmytro Mitin


Use he slick-postgreSQL extensions: https://github.com/tminglei/slick-pg

more info: How to pass an array to a slick SQL plain query?

implicit val setIntArray: SetParameter[Array[Int]] = mkArraySetParameter[Int](...)
like image 28
David Portabella Avatar answered Oct 20 '25 02:10

David Portabella