Created
November 17, 2014 04:57
-
-
Save alexlee85/352b61386abc501b2334 to your computer and use it in GitHub Desktop.
Scala Slick dynamic filter
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 QueryHelper[T, E](query: Query[T, E, Seq]) { | |
def optionFilter[X, R: CanBeQueryCondition](name: Option[X])(f: (T, X) => R) = | |
name.map(v => query.withFilter(f(_, v))).getOrElse(query) | |
} | |
query.optionFilter(name)(_.name === _) | |
.optionFilter(email)(_.email === _).list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! I was searching for a solution of sharing a join query, and this gist really helped me! Very short and concise, but really useful. Just wanted to say thank you for sharing :)