Database.forURL(
"jdbc:h2:data/dbname;TRACE_LEVEL_SYSTEM_OUT=2",
driver = "org.h2.Driver")
試しに下記のような最低限のコードを動かしてみる。
import scala.slick.driver.H2Driver.simple._
import scala.slick.session.Database
import scala.slick.lifted.Query
import scala.slick.session.Session
object H2DebugSample extends App {
val url = "jdbc:h2:data/dbname;TRACE_LEVEL_SYSTEM_OUT=2"
val driver = "org.h2.Driver"
Database.forURL(url, driver = driver) withSession { implicit session: Session =>
Foo.ddl.create
Foo.insertAll(FooItem(1, "hoge"), FooItem(2, "fuga"))
Query(Foo).where(_.id is 1).list.foreach(println)
}
}
case class FooItem(id: Int, value: String)
object Foo extends Table[FooItem]("foo") {
def id = column[Int]("id", O.PrimaryKey)
def value = column[String]("value")
def * = id ~ value <> (FooItem, FooItem.unapply _)
}
このコードを動かすと、下記のような情報が標準出力に出てくれる。手軽に設定できるので割と便利だった。
/*SQL t:1*/create table \"foo\" (\"id\" INTEGER NOT NULL PRIMARY KEY,\"value\" VARCHAR NOT NULL);
/*SQL l:45 #:1 t:1*/INSERT INTO \"foo\" (\"id\",\"value\") VALUES (?,?) {1: 1, 2: 'hoge'};
/*SQL l:45 #:1*/INSERT INTO \"foo\" (\"id\",\"value\") VALUES (?,?) {1: 2, 2: 'fuga'};
/*SQL #:1*/select x2.\"id\", x2.\"value\" from \"foo\" x2 where x2.\"id\" = 1;