Skip to content

Commit

Permalink
easier access to logging, generated sql, eclipse
Browse files Browse the repository at this point in the history
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
cvogt committed Oct 17, 2012
1 parent dfcb218 commit f4b2355
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
18 changes: 12 additions & 6 deletions build.sbt
@@ -1,19 +1,25 @@
organization := "com.typesafe" organization := "com.typesafe"


name := "slick-examples" name := "slick-presentation"


version := "0.11.1" version := "1.0"


scalaVersion := "2.10.0-M7" scalaVersion := "2.10.0-M7"


scalacOptions += "-deprecation" scalacOptions += "-deprecation"


libraryDependencies ++= List( libraryDependencies ++= List(
"com.typesafe" % "slick_2.10.0-M7" % "0.11.1", "com.typesafe" % "slick_2.10.0-M7" % "0.11.1"
"org.slf4j" % "slf4j-nop" % "1.6.4", ,"com.h2database" % "h2" % "1.3.166"
"com.h2database" % "h2" % "1.3.166", ,"org.xerial" % "sqlite-jdbc" % "3.6.20"
"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.apache.derby" % "derby" % "10.6.1.0",
"org.hsqldb" % "hsqldb" % "2.0.0", "org.hsqldb" % "hsqldb" % "2.0.0",
"postgresql" % "postgresql" % "8.4-701.jdbc4", "postgresql" % "postgresql" % "8.4-701.jdbc4",
Expand Down
1 change: 1 addition & 0 deletions project/plugins.sbt
@@ -0,0 +1 @@
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0")
37 changes: 25 additions & 12 deletions src/main/scala/SlickPresentation.scala
Expand Up @@ -46,19 +46,32 @@ object SlickPresentation extends App{
} }


session.withTransaction{ session.withTransaction{
// print certain people with their tasks // query people above 21 with their tasks
val somePeople = Persons.above(21) val somePeople = Persons.above(21).sortBy(_.name)
val theirTasks = for( t <- Tasks; if t.personId in somePeople.map(_.id) ) yield t 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") // print results (using Scala 2.10 string interpolation)
println("-"*80) print(
println( "=== people and their tasks ===" ) s"""
somePeople.sortBy(_.name).foreach{ p =>
print( p.name + ": " )
println( theirTasks.filter(_.personId === p.id).map(_.title).list.mkString(", ") ) === result ===
} ${results}
println("-"*80)
println("\n\n") === generated sql queries ===
somePeople: ${somePeople.selectStatement}

theirTasks: ${theirTasks.selectStatement}



"""
)
} }
session.close() session.close()
} }

0 comments on commit f4b2355

Please sign in to comment.