Is there a way to perform a query like this in Slick:
"select * from foo where id IN (select other_id from bar where status = 'damaged')"
Thanks
for{
f <- foo,
b <- bar if (b.status === 'damaged' && f.id === b.other_id)
} yield f
this produces
select x2."id" from "foo" x2, "bar" x3
where (x2."id" = x3."other_id") and (x3."status" = 'damaged')
which is equivalent in terms of rows returned. If you need that exact query for some reason you'll probably need to either extend slick or use a static query.
yes:
the imports:
import scala.slick.jdbc.{ GetResult, StaticQuery => Q }
import Q.interpolation
the result, and the conversion to the result:
case class FooResult(id: Int, name: String)
implicit val getPersonResult = GetResult(r => FooResult(r.<<, r.<<))
your query:
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With