【发布时间】:2021-07-12 13:54:19
【问题描述】:
我是 scala 的初学者,我正在使用 slick 和 postgres 作为我的 model API 之一
下面是我的函数,它以Id: String 作为输入并形成一个left inner join query,它返回matching Ids(String) from DB table。
def getCountByID(
Id: String
): Future[Either[Throwable, Int]] = {
val innerJoin = for {
(rel,a) <- executors joinLeft executors on ( (e1, e2) => {
e1.column1 === e2.column1 && e1.column2 === e2.column2
} ) if rel.id === Id
} yield a.map(_.id)
db.run(innerJoin.result) # Seq of options => FixedSqlStreamingAction[Seq[Option[String]],Option[String],dbio.Effect.Read]
}
db.run 给了我一个 Seq of options 。我想返回 Future 和 Either length 或 Ids 或一些 throwable exception 。我怎样才能在这里达到同样的效果。
【问题讨论】: