Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slick where/filter/withFilter

Tags:

scala

slick

In slick (1.0), what is the difference between doing .where(), .filter() and .withFilter() on a Table?

In the API they have similar signature but it's not clear how they differ:

def filter[T]            (f: (E) ⇒ T)(implicit wt:   CanBeQueryCondition[T]): Query[E, U]
def where[T <: Column[_]](f: (E) ⇒ T)(implicit arg0: CanBeQueryCondition[T]): Query[E, U]
def withFilter[T]        (f: (E) ⇒ T)(implicit arg0: CanBeQueryCondition[T]): Query[E, U]
like image 976
OlivierBlanvillain Avatar asked Jun 05 '13 15:06

OlivierBlanvillain


1 Answers

According to the source all this methods are the same:

def withFilter[T : CanBeQueryCondition](f: E => T) = filter(f)
def where[T <: Column[_] : CanBeQueryCondition](f: E => T) = filter(f)

filter is the common method to filter collections in scala. There is filter method in collections, Option, Future, Try and so on.

withFilter is there for for comprehensions. if statement in for comprehensions is translated into call of withFilter.

I guess where is added by analogy with SQL where statement.

like image 98
senia Avatar answered Oct 09 '22 18:10

senia