-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from slick/update-for-scala-changes
Update for Scala changes
- Loading branch information
Showing
1 changed file
with
29 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,29 @@ | ||
object Tables extends { | ||
// or just use object demo.Tables, which is hard-wired to the driver stated during generation | ||
val profile = slick.jdbc.H2Profile | ||
} with demo.Tables | ||
|
||
|
||
import scala.concurrent.Await | ||
import scala.concurrent.duration._ | ||
import scala.language.postfixOps | ||
|
||
import Tables._ | ||
import Tables.profile.api._ | ||
import scala.concurrent.ExecutionContext.Implicits.global | ||
|
||
|
||
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) } | ||
|
||
Await.result(db.run(q.result).map { result => | ||
println(result.groupBy { case (co, cp) => co } | ||
.mapValues(_.map { case (co, cp) => cp }) | ||
.mkString("\n") | ||
) | ||
}, 60 seconds) | ||
} | ||
object Tables extends demo.Tables { | ||
// or just use object demo.Tables, which is hard-wired to the driver stated during generation | ||
override val profile = slick.jdbc.H2Profile | ||
} | ||
|
||
|
||
import scala.concurrent.Await | ||
import scala.concurrent.duration._ | ||
import scala.language.postfixOps | ||
|
||
import Tables._ | ||
import Tables.profile.api._ | ||
import scala.concurrent.ExecutionContext.Implicits.global | ||
|
||
|
||
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) } | ||
|
||
Await.result(db.run(q.result).map { result => | ||
println(result.groupMap(_._1)(_._2).mkString("\n")) | ||
}, 60 seconds) | ||
} |