Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

easier access to logging, generated sql, eclipse

fixed: theirTasks now executed before the loop
changed scala to print generated sql
changed build.sbt to easily enable logging
added sbt eclipse plugin to easily generate eclipse project files
  • Loading branch information...
commit f4b2355693c94d6d781df95c7b14879af0ce93e3 1 parent dfcb218
Jan Christopher Vogt authored
18 build.sbt
View
@@ -1,19 +1,25 @@
organization := "com.typesafe"
-name := "slick-examples"
+name := "slick-presentation"
-version := "0.11.1"
+version := "1.0"
scalaVersion := "2.10.0-M7"
scalacOptions += "-deprecation"
libraryDependencies ++= List(
- "com.typesafe" % "slick_2.10.0-M7" % "0.11.1",
- "org.slf4j" % "slf4j-nop" % "1.6.4",
- "com.h2database" % "h2" % "1.3.166",
- "org.xerial" % "sqlite-jdbc" % "3.6.20"
+ "com.typesafe" % "slick_2.10.0-M7" % "0.11.1"
+ ,"com.h2database" % "h2" % "1.3.166"
+ ,"org.xerial" % "sqlite-jdbc" % "3.6.20"
+ ,"org.slf4j" % "slf4j-nop" % "1.6.4" // <- disables logging
/*
+// enables logging
+ ,"org.slf4j" % "slf4j-api" % "1.6.4"
+ ,"ch.qos.logback" % "logback-classic" % "0.9.28"
+*/
+/*
+// Other database drivers
"org.apache.derby" % "derby" % "10.6.1.0",
"org.hsqldb" % "hsqldb" % "2.0.0",
"postgresql" % "postgresql" % "8.4-701.jdbc4",
1  project/plugins.sbt
View
@@ -0,0 +1 @@
+addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0")
37 src/main/scala/SlickPresentation.scala
View
@@ -46,19 +46,32 @@ object SlickPresentation extends App{
}
session.withTransaction{
- // print certain people with their tasks
- val somePeople = Persons.above(21)
- val theirTasks = for( t <- Tasks; if t.personId in somePeople.map(_.id) ) yield t
+ // query people above 21 with their tasks
+ val somePeople = Persons.above(21).sortBy(_.name)
+ val theirTasks = (for( t <- Tasks; if t.personId in somePeople.map(_.id) ) yield t)
+ val theirTasksResults = theirTasks.list
+
+ val results = somePeople.list.map( p =>
+ p.name + ": " + theirTasksResults.filter(_.personId == p.id).map(_.title).mkString(", ")
+ ).mkString("\n")
- println("\n\n")
- println("-"*80)
- println( "=== people and their tasks ===" )
- somePeople.sortBy(_.name).foreach{ p =>
- print( p.name + ": " )
- println( theirTasks.filter(_.personId === p.id).map(_.title).list.mkString(", ") )
- }
- println("-"*80)
- println("\n\n")
+ // print results (using Scala 2.10 string interpolation)
+ print(
+s"""
+
+
+=== result ===
+${results}
+
+=== generated sql queries ===
+somePeople: ${somePeople.selectStatement}
+
+theirTasks: ${theirTasks.selectStatement}
+
+
+
+"""
+ )
}
session.close()
}
Please sign in to comment.
Something went wrong with that request. Please try again.