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]
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With