I know as of slick 2.1. one can use ConstColumn for take and drop in precompiled Query's using "Compiled".
private val findXXXCompiled = Compiled {
(someId:Column[Long], sortBy:???, drop:ConstColumn[Long], take:ConstColumn[Long]) =>
val q = findXXX(someId) // returns a Query
// I want to use query composition on "q" in order to further restrict my result:
q.sortBy {
case (_, name, state) => sortBy match {
case ??? => name.asc
case ??? => name.desc
case ??? => state.asc
case ??? => state.desc
}
}.drop(drop).take(take) // possible since slick 2.1. as described above using type ConstColumn
}
The example code above is being triggered by a user from a UI with a table layout. If a user clicks on the "name" header then the table should be sorted according to the "name" - the same for "state".
The aspect I can't get to work is combine precompilation with dynamic sorting (depeding on the clicked header in the table layout). Dynamic sorting of course works when not precompiling a query. But as method "findXXX" is pretty complex I definately need to precompile as of performance reasons. Any hint on how to achive precompilation with dynamic sorting?
See also: https://groups.google.com/forum/#!topic/scalaquery/my4EYt51qEM
ConstColumn[String]
but guess that won't work. best use a compiled query per sorting and use a map to look them up, that solves your problem - assume that's what you used? guess hard to write without repeating some code but should still be rather compact. like me to make a suggestion? – Detoxify