How to return compound types in Slick's Case-If-Then-Else

半世苍凉 提交于 2019-12-08 08:22:51

问题


I just start dipping my toe into Slick.

In the coffee-supplier example, I try "Case If Then Else" like this:

val q = coffees.withFilter(_.price > 9.0).flatMap({ c =>
  suppliers.withFilter(_.id == c.supID).map({ s =>
    val t = c.name > s.name
    Case If t Then { (c.name, s.name) } Else { (s.name, c.name) }
  })
})

The compiler emits an error:

could not find implicit value for evidence parameter of type scala.slick.ast.TypedType[(scala.slick.lifted.Column[String], scala.slick.lifted.Column[String])]
        Case If t Then { (c.name, s.name) } Else { (s.name, c.name) }
                         ^

Much the same error apears for other compound types like List as well. I guess I'm on my own to define an implicit for the type in question but I'm not sure where to start.


回答1:


Currently not support, I created a ticket: https://github.com/slick/slick/issues/866

Workaround: Write individual If Then constructs for each scalar value




回答2:


Try:

    val q = coffees.withFilter(_.price > 9.0).flatMap({ c =>
      suppliers.withFilter(_.id == c.supID).map{ s =>
      (Case If c.name > s.name Then c.name Else s.name,
       Case If c.name > s.name Then s.name Else c.name)}})


来源:https://stackoverflow.com/questions/24383717/how-to-return-compound-types-in-slicks-case-if-then-else

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!