Operations on columns
In the previous section, you learned about the different invokers and how they mapped to SQL statements. We brushed over the methods supported by columns themselves, however: we can compare for equality using ===
, but what other operations are supported by Slick columns?
Most of the SQL functions are supported. For instance, to get the total donations to candidates whose name starts with "O"
, we could run the following:
scala> db.withSession { implicit session => Tables.transactions.filter { _.candidate.startsWith("O") }.take(5).list } List[Tables.Transactions#TableElementType] = List(Transaction(Some(1594098)...
Similarly, to count donations that happened between January 1, 2011 and February 1, 2011, we can use the .between
method on the date
column:
scala> val dateParser = new SimpleDateFormat("dd-MM-yyyy") dateParser: java.text.SimpleDateFormat = SimpleDateFormat scala> val startDate = new java.sql.Date(dateParser.parse("01-01-2011").getTime...