使用Slick"选择"

Pab*_*dez 5 scala slick

有没有办法在Slick中执行这样的查询:

"select * from foo where id IN (select other_id from bar where status = 'damaged')"
Run Code Online (Sandbox Code Playgroud)

谢谢

bar*_*sef 1

是的:

进口:

import scala.slick.jdbc.{ GetResult, StaticQuery => Q }

import Q.interpolation

结果以及结果的转换:

case class FooResult(id: Int, name: String)

implicit val getPersonResult = GetResult(r => FooResult(r.<<, r.<<))

您的查询:

val status = "damaged"

val q = Q.query[String,FooResult]("select * from foo where id IN (select other_id from bar where status = ?)")

val result = q.list(status)