scala オブジェクトにサンプル DB がありますが、テーブルが作成されません。
初期化を呼び出してから addEntries を呼び出すと、JDBC レイヤーによってテーブルが存在しないという例外が発生します。どこが間違っていますか?
object ExampleCompanyH2TestDb {
val Companies = new Table[(Int, Int, String, String, String, Double,Double)]("COMPANIES") {
def id = column[Int]("COMPANY_ID", O.PrimaryKey)
// This is the primary key column
def id2 = column[Int]("COMPANY_ID2")
def name = column[String]("COMPANY_NAME")
def country = column[String]("COUNTRY")
def city = column[String]("CITY")
def latitude = column[Double]("LATITUDE")
def longitude = column[Double]("LONGITUDE")
// Every table needs a * projection with the same type as the
table's type parameter
def * = id ~ id2 ~ name ~ country ~ city ~ latitude ~ longitude
}
// Connect to the database and execute the following block within a session
val db = Database.forURL("jdbc:h2:mem:test1", driver = "org.h2.Driver")
def initialize = {
db withSession {
// The session is never named explicitly. It is bound to the current
// thread as the threadLocalSession that we imported
(Companies.ddl).create
}
}
// Create the tables, including primary and foreign keys
def addEntries(entries: Iterable[ExampleCompany]) {
val asTuples = entries.map {
ExampleCompany.unapply
}.collect {
case Some(entry) => entry
}.toSeq
db withSession {
Companies.insertAll(asTuples: _*)
}
}