如何在 Slick 的 Case-If-Then-Else 中返回复合类型 [英] How to return compound types in Slick's Case-If-Then-Else

查看:40
本文介绍了如何在 Slick 的 Case-If-Then-Else 中返回复合类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始将脚趾浸入 Slick 中.

I just start dipping my toe into Slick.

在咖啡供应商示例中,我尝试Case If Then Else",如下所示:

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) }
  })
})

编译器发出错误:

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) }
                         ^

对于其他复合类型(如 List),也会出现很多相同的错误.我想我需要自己为所讨论的类型定义一个隐式,但我不确定从哪里开始.

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.

推荐答案

目前不支持,我创建了一个票:https://github.com/slick/slick/issues/866

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

解决方法:为每个标量值编写单独的 If Then 构造

Workaround: Write individual If Then constructs for each scalar value

这篇关于如何在 Slick 的 Case-If-Then-Else 中返回复合类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆