How can I extract results of aggregate queries in slick?

一笑奈何 提交于 2019-12-24 03:05:10

问题


I am simply trying to check if any rows that meet certain conditions exist:

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

I am getting this error:

polymorphic expression cannot be instantiated to expected type;
[error]  found   : [R]scala.slick.lifted.Column[R]
[error]  required: Boolean

Any idea what is going on? For now I am just turning the results into a scala list (instead of .length I have .list.length) and checking the length of that, but I should not have to do that. I could not find any methods on columns to help me extract the value.


回答1:


Use: .length.run

.length returns a Column[Int], which is implictly converted to an Executor when you call the method .run



来源:https://stackoverflow.com/questions/20277958/how-can-i-extract-results-of-aggregate-queries-in-slick

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!