Invokers

Invokers are the components of a Slick query that build up the SQL select statement. Slick exposes a variety of invokers that allow the construction of complex queries. Let's look at some of these invokers here:

  • The map invoker is useful to select individual columns or apply operations to columns:
    scala> db.withSession { implicit session =>
      Tables.transactions.map {
        _.candidate 
      }.take(5).list       
    }
    List[String] = List(Obama, Barack, Paul, Ron, Paul, Ron, Paul, Ron, Obama, Barack)
    
  • The filter invoker is the equivalent of the WHERE statements in SQL. Note that Slick fields must be compared using ===:
    scala> db.withSession { implicit session => 
      Tables.transactions.filter {
        _.candidate === "Obama, Barack"
      }.take(5).list
    }
    List[Tables.Transactions#TableElementType] ...

Get Scala for Data Science now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.