Search code examples
scalaslick

Is it possible to implement filters with multiple predicates?


I'm having trouble figuring out how to work with multiple predicates in slick.

For a simple example, imagine a SQL style AND filter where a user matches a specified first and last name:

def getByName(first: String, last: String) = {
  users // TableQuery[Users]
    .filter(_.userFirstName === first)
    .filter(_.userLastName === last)
    .result
}

Is there a more idiomatic (and more performant) implementation of complex filters with multiple predicates in slick or am I taking the wrong approach?


Solution

  • Try

    def getByName(first: String, last: String) = {
      users
        .filter(user => user.userFirstName === first && user.userLastName === last)
        .result
    }