Created
September 25, 2015 13:36
-
-
Save leandrob13/09c6bfb333e106cf5931 to your computer and use it in GitHub Desktop.
Based on MaybeFilter (https://gist.github.com/cvogt/9193220), it uses implicit class to add the methods to the Query objects. FilteredBy works for filtering lists and it returns the query if no filters were applied. FoundBy works for finding a single register, if no filter defined it returns None.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit class OptionFilter[ X, Y ]( query: Query[ X, Y, Seq ] ) { | |
def filteredBy[ T ]( op: Option[ T ] )( f: ( X, T ) => Column[ Option[ Boolean ] ] ): Query[ X, Y, Seq ] = { | |
op map { o => query.filter( f( _, o ) ) } getOrElse { query } | |
} | |
def foundBy[ T ]( op: Option[ T ] )( f: ( X, T ) => Column[ Option[ Boolean ] ] ): Query[ X, Y, Seq ] = { | |
op map { o => query.filter( f( _, o ) ) } getOrElse { query.take( 0 ) } | |
} | |
} |
Yes, I have been using it but I have made some changes to it. If you are still interested I can share it with you
Here is the new one: https://gist.github.com/leandrob13/a50f61db5a81d36dd5d35820fd9ca67e
I promise I will show you how to use it.
Here you go, a full example in slick 3.1: https://medium.com/pragmatic-scala/filter-ops-with-slick-3-1-1b0c4ec59bb1#.vb2kipa2a
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you know is this will work with Slick 3.x and do you have any example of putting it into practice?