Hi,
How would you all write this query? Bare with me here as I'm very new to SLICK. Here's a simplified representation of my schema:
object MetadataTable extends Table[(String, String, ...)]("METADATA") {
def uuid = column[String]("uuid", O.PrimaryKey)
def tag = column[String]("tag")
...
def idxTag = index("idx_tag", tag, unique = true)
def * = uuid ~ tag ~ ...
}
I have obviously inserted ... where irrelevant non-keyed columns exist.
Now I want to retrieve all rows with a query generating function like the following:
def getAllMetadataByTagRange(start: Option[String], stop: Option[String], limit: Int, dir: ListDirection) = {
val query = for { m <- MetadataTable } yield m.*
val q1 = start.fold(query)(s => query.filter(_._2 >= s))
val q2 = stop.fold(q1)(s => query.filter(_._2 < stop))
val q3 = if(dir == ListDirection.LEFT) q2.sortBy(_._2) else q2.sortBy(_._2).desc
q3.take(limit)
}
My first problem is that the 'desc' doesn't compile, it fails with:
error: could not find implicit value for evidence parameter of type scala.slick.lifted.TypeMapper[scala.slick.lifted.Query[scala.slick.lifted.Projection3[String,String,Option[String]],(String, String, Option[String])]]
if(dir == ListDirection.LEFT) q2.sortBy(_._2) else q2.sortBy(_._2).desc
How do I do the desc sort? How can I better write this parameterized query?
To sum up the query in English:
Return all rows lexically between start (inclusive) and stop (exclusive)... If the start and stop are supplied. Sort and limit the returned rows.
thanks for your help!
Adam