Slick - compiled with dynamic sortBy

I know how to spot 2.1. You can use ConstColumn to take and discard a precompiled query 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 above code sample is launched by the user from the user interface with a table layout. If the user clicks on the header "name", then the table should be sorted by "name" - the same for "state".

An aspect that I cannot get is to combine pre-compilation with dynamic sorting (deleting by clicking on the header in the table layout). Dynamic sorting, of course, works when the query is not precompiled. But since the "findXXX" method is quite complicated, I definitely need to precompile it for performance reasons. There is a hint how to achieve pre-compilation using dynamic sorting?

See also: https://groups.google.com/forum/#!topic/scalaquery/my4EYt51qEM

+10
source share

Source: https://habr.com/ru/post/978444/


All Articles