我只是想检查是否存在满足特定条件的行:
// Method defined on type T
def exists(some_data : Long, other_data : Long) : Boolean = DB.withSession { implicit session : Session =>
(for {
row <- table // table is a Table[T]
if row.some_data =!= some_data
if row.other_data === other_data
} yield row).length > 0
}
我收到此错误:
polymorphic expression cannot be instantiated to expected type;
[error] found : [R]scala.slick.lifted.Column[R]
[error] required: Boolean
知道发生了什么吗?现在我只是将结果转换为 scala 列表(而不是 .length
我有 .list.length
)并检查其长度,但我不应该要做到这一点。我在列上找不到任何方法来帮助我提取值。
最佳答案
使用:.length.run
.length
returns a Column[Int] ,即implictly converted to an Executor当您调用the method .run
时
关于scala - 如何在 slick 中提取聚合查询的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20277958/