【问题标题】:How can I extract results of aggregate queries in slick?如何在 slick 中提取聚合查询的结果?
【发布时间】:2014-05-27 08:15:12
【问题描述】:

我只是想检查是否存在满足某些条件的行:

  // 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)并检查它的长度,但我不应该这样做。我在列上找不到任何方法来帮助我提取值。

【问题讨论】:

    标签: scala slick


    【解决方案1】:

    使用:.length.run

    .lengthreturns a Column[Int],当你调用the method .run时是implictly converted to an Executor

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-22
      • 2018-12-11
      • 1970-01-01
      相关资源
      最近更新 更多