7

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]
OlivierBlanvillain
  • 7,701
  • 4
  • 32
  • 51

1 Answers1

9

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.

Community
  • 1
  • 1
senia
  • 37,745
  • 4
  • 88
  • 129