In association with heise online

12 February 2013, 15:29

Slick 1.0 simplifies database access with Scala

  • Twitter
  • Facebook
  • submit to slashdot
  • StumbleUpon
  • submit to reddit

Slick logo

Slick, a database access library for the Scala language designed by Typesafe, has reached its 1.0 release milestone. Slick allows developers to write their database queries in Scala instead of a database native language like SQL, reaping the benefits of static checking and compile time safety afforded by the library's query compiler. The tool can be extended to interface with several different database backends and allows developers to access the data stored in it as if they were directly using Scala collections. For example, creating a table would look like:

object Coffees extends Table[(String, Int, Double)]("COFFEES") {
def name = column[String]("COF_NAME", O.PrimaryKey)
def supID = column[Int]("SUP_ID")
def price = column[Double]("PRICE")
def * = name ~ supID ~ price

while inserting values would simply be:

("Colombian", 101, 7.99),
("Colombian_Decaf", 101, 8.99),
("French_Roast_Decaf", 49, 9.99)

Queries can then be expressed as a yielding function which can be enumerated:

val q = for {
c <- Coffees if c.supID === 101
// ^ comparing Rep[Int] to Rep[Int]!
} yield (, c.price)


q.foreach { case (n, p) => println(n + ": " + p) }

With Slick 1.0, the developers are delivering the first major update to the library since it was introduced in August 2012. The new version introduces improvements such as the ability to immediately retrieve automatically generated primary keys:

val ids = returning insertAll ("foo", "bar") 

Supported databases include MySQL, SQLite, PostgreSQL, Microsoft's SQL Server and Access. Slick 1.0 also includes new connectors for Oracle and DB2 databases as part of the commercially licensed Slick Extensions provided by Typesafe. A full list is available as part of the library's online documentation.

Another new feature is Slick TestKit which contains most of the package's unit tests in a reusable form and allows users to test existing database drivers or drivers that the users have written themselves. The implementation of capability flags allows developers to compensate for minor differences in the abilities of different database implementations. Other improvements are listed in the official release announcement.

Slick 1.0 is available for Scala 2.10.0 from the project's web site. The library's source code is available under a BSD licence from GitHub.


Print Version | Send by email | Permalink:

  • July's Community Calendar

The H Open

The H Security

The H Developer

The H Internet Toolkit