gpt4 book ai didi

scala - Slick:选项列过滤

转载 作者:行者123 更新时间:2023-12-02 09:35:39 25 4
gpt4 key购买 nike

我想做这样的事情(这是一个为了简化我的实际问题而编造的例子):

def findByGender(isMale: Option[Boolean]) = {
People.filter(row => row.name.isNotNull && isMale match {
case Some(true) => row.wife.isNotNull // find rows where wife column is not null
case Some(false) => row.wife.isNull // find rows where wife column is null
case None => true // select everything
})
}

由于最后一个“true”,因此无法编译。有更好的方法吗?

最佳答案

您必须将其设为Column[Boolean]:

def findByGender(isMale: Option[Boolean]) = {
People.filter(row => row.name.isNotNull && isMale match {
case Some(true) => row.wife.isNotNull // find rows where wife column is not null
case Some(false) => row.wife.isNull // find rows where wife column is null
case None => LiteralColumn(true) // select everything
})
}

关于scala - Slick:选项列过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26554224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com