Slick(2) – study note

1. Database Connection:

There are three ways to do Database Connection:

  1. using a JDBC URL
  2. using a DataSource
  3. using a JNDI name


  1. We can use the Session object’s withTransaction method to create a transaction. The block passed to its executed in a single transaction.

2. Queries:

  • sorting and filtering
  • joining:
    • explicit join:
      • innerJoin
      • leftJoin
      • rightJoin
      • outerJoin
      • zip
    • implicit join: an implicit cross-join is created with a flagMap operation on a Query (i.e. by introducing more than one generator in a for comprehension)
  • unions:
    • Two queries can be concatenated with the ++ (or unionAll) and union operators if they have compatible types. Unlike union which filters out duplicate values, ++ simply concatenates the results of the individual queries, which is usually more efficient.
  • aggregation:
    • min
    • max
    • sum
    • avg
    • length
    • exists

3. Deleting:

A query for deleting must only select from a single table.

4. Inserting:

Inserts are done based on a projection of columns from a single table. When you include an AutoInc column in an insert operation, it is silently ignored, so that the database can generate the proper value.

5. Updating:

The query must only return raw columns (not computed values) selected from a single table.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s