问题
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