我正在尝试 ScalaQuery,它真的很棒。我可以使用 Scala 类定义数据库表,并轻松查询它。
但是我想知道,在下面的代码中,我如何检查一个表是否存在,这样我就不会调用 'Table.ddl.create' 两次并在我运行这个程序两次时得到一个异常?
object Users extends Table[(Int, String, String)]("Users") {
def id = column[Int]("id")
def first = column[String]("first")
def last = column[String]("last")
def * = id ~ first ~ last
}
object Main
{
val database = Database.forURL("jdbc:sqlite:sample.db", driver = "org.sqlite.JDBC")
def main(args: Array[String]) {
database withSession {
// How could I know table Users is alrady in the DB?
if ( ??? ) {
Users.ddl.create
}
}
}
}