有没有办法使用 slick 3.2+ 创建嵌套选择?
基本上我需要的所有内容都在这里描述如何在 select 子句中编写嵌套查询 https://stackoverflow.com/questions/14920153/how-to-write-nested-queries-in-select-clause
然而在 slick 3.2 上这种方法不起作用。
如果你有桌子Users
(id:UUID,电子邮件:字符串)和Persons
(userId: UUID, name: String, surname: String) 比查询
select email
from Users
where id in (select userId
from Persons
where name = 'John'
and surname = 'Smith')
看起来有点像:
users
.filter(
_.id in persons
.filter(p => p.name === "John" && p.surname === "Smith")
.map(_.userId)
)
.map(_.email)
.result
你需要记住的事情:
-
Query
类型不是DBIO
(nor DBIOAction
) - 如果你想编写查询,你需要在调用之前完成.result
on them
- 当您在条件使用中使用子查询时
in
代替inSet
无论您是否使用,都应遵循相同的原则in
, join
, etc.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)