7

有人可以告诉我如何使用 slick 的提升嵌入将表列与 NULL 进行比较。

我想在mysql中实现什么:

select * from Users where email = '<some_email_addr>' and ( removed = NULL OR removed <= 1 )

当我尝试时,它在 x.removed === null 处给我一个错误:

val q = for {
    x <- Users
        if x.email === email && ( x.removed === null || x.removed <= 1 )
} yield x.removed

谢谢

4

3 回答 3

16

尝试:

x.removed.isNull

我想这就是你要找的

于 2013-07-16T11:36:06.183 回答
7

正如 daaatz 所说,根据http://slick.typesafe.com/doc/2.1.0/upgrade.html#isnull-and-isnotnull您应该使用isEmpty,但它仅适用于 Option 列。一种解决方法是x.removed.?.isEmpty.

于 2014-09-10T11:38:44.310 回答
4

尝试

x.removed.isEmpty()

scala 中没有空值;-)

于 2013-07-16T06:58:09.787 回答