[英]implicit value for slick.jdbc.SetParameter[List[Int]]
I have a raw slick query backed by PostgreSQL.我有一个由 PostgreSQL 支持的原始光滑查询。 I want to run a query like this:
select something from my_table where action in (1,2,3)
.我想运行这样的查询:
select something from my_table where action in (1,2,3)
。 Note that action is an integer
field in my_table
注意 action 是
my_table
一个integer
字段
I'm getting a compilation error in my method below:我在下面的方法中遇到编译错误:
could not find implicit value for parameter e: slick.jdbc.SetParameter[List[Int]]
找不到参数 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?如何显式设置
List[Int]
参数以便我可以成功运行in
查询?
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 http://slick.lightbend.com/doc/3.3.0/sql.html#splicing-literal-values
https://www.w3schools.com/sql/sql_in.asp https://www.w3schools.com/sql/sql_in.asp
Use he slick-postgreSQL extensions: https://github.com/tminglei/slick-pg使用 slick-postgreSQL 扩展: https : //github.com/tminglei/slick-pg
more info: How to pass an array to a slick SQL plain query?更多信息: 如何将数组传递给光滑的 SQL 纯查询?
implicit val setIntArray: SetParameter[Array[Int]] = mkArraySetParameter[Int](...)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.