diff options
author | Christopher Vogt <christopher.vogt@epfl.ch> | 2013-12-23 08:11:12 +0100 |
---|---|---|
committer | Christopher Vogt <christopher.vogt@epfl.ch> | 2013-12-24 18:22:21 +0100 |
commit | c952071e9beb0124360b65b127ab571dd8d9f970 (patch) | |
tree | 48ce3b33000c57649f9a5189964e5ddbe9ccaf48 /src/main/scala | |
download | slick-codegen-example-c952071e9beb0124360b65b127ab571dd8d9f970.tar.gz slick-codegen-example-c952071e9beb0124360b65b127ab571dd8d9f970.tar.bz2 slick-codegen-example-c952071e9beb0124360b65b127ab571dd8d9f970.zip |
Initial code example2.0.0-RC1
Diffstat (limited to 'src/main/scala')
-rw-r--r-- | src/main/scala/Example.scala | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/main/scala/Example.scala b/src/main/scala/Example.scala new file mode 100644 index 0000000..85a6ed3 --- /dev/null +++ b/src/main/scala/Example.scala @@ -0,0 +1,22 @@ +object Tables extends demo.Tables{ // or just use object demo.Tables, which is hard-wired to the driver stated during generation
+ val profile = scala.slick.driver.H2Driver
+}
+import Tables._
+import Tables.profile.simple._
+
+object Example extends App {
+ // connection info for a pre-populated throw-away, in-memory db for this demo, which is freshly initialized on every run
+ val url = "jdbc:h2:mem:test;INIT=runscript from 'src/main/sql/create.sql'"
+ val db = Database.forURL(url, driver = "org.h2.Driver")
+
+ // Using generated code. Our Build.sbt makes sure they are generated before compilation.
+ val q = Companies.join(Computers).on(_.id === _.manufacturerId)
+ .map{ case (co,cp) => (co.name, cp.name) }
+
+ db.withTransaction { implicit session =>
+ println( q.run.groupBy{ case (co,cp) => co }
+ .mapValues(_.map{ case (co,cp) => cp })
+ .mkString("\n")
+ )
+ }
+}
|