简体   繁体   中英

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

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?

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

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](...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM