tain",price=828.0)
41 def getNameAndPrice(n: Int) = coffees.filter(_.id === n)
42 .map(r => (r.name,r.price)).result.head
43
44 val actions = for {
45 _ <- coffees.schema.create
46 _ <- qDelete
47 c1 <- qAdd1
48 c2 <- qAdd2
49 (n1,p1) <- getNameAndPrice(c1)
50 (n2,p2) <- getNameAndPrice(c2)
51 } yield (n1,p1,n2,p2)
52 import java.sql.SQLException
53 import scala.concurrent.Await
54 import scala.concurrent.duration._
55 val db = Database.forURL("jdbc:h2:mem:demo", driver="org.h2.Driver")
56 Await.result(
57 db.run(actions.transactionally).map { res =>
58 println(s"Add coffee: ${res._1},${res._2} and ${res._3},${res._4}")
59 }.recover {
60 case e: SQLException => println("Caught exception: " + e.getMessage)
61 }, Duration.Inf)
62
63 }
|