mushroom
mushroom

Reputation: 6279

How can I extract results of aggregate queries in slick?

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.

Upvotes: 2

Views: 705

Answers (1)

cvogt
cvogt

Reputation: 11270

Use: .length.run

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

Upvotes: 3

Related Questions