class DbInstrument(tag : Tag) extends Table[(Int, String)](tag, "instruments") {
def id = column[Int]("id", O.PrimaryKey)
def symbol = column[String]("symbol", O.PrimaryKey)
def * = (id, symbol)
}
class DB {
val instruments = TableQuery[DbInstrument]
def init() = {
try {
val db = Database.forURL("jdbc:h2:~/accel", driver = "org.h2.Driver")
val createCmd = DBIO.seq(instruments.schema.create, instruments += (1, "symbol123"))
val res = db.run(createCmd)
println(res)
}
catch {
case ex : Exception => println(">> DB Exception: " + ex)
}
}
}
Then I call it in my main function:
object MyApp extends App {
val d = new DB()
d.init()
while (true) {
Thread.sleep(1000 * 60 * 60)
}
}
I found that the h2 database is created whereas the table is not created and no data is inserted.
Can anyone help inspect what's wrong with the source code? Thanks in advance.
