February 2017
Beginner to intermediate
1100 pages
25h 19m
English
Commonly, especially during development, you might start the script by dropping the table if it exists, then recreating it. We can find if a table is defined by accessing the database metadata through the MTable object. To get a list of tables with name matching a certain pattern, we can run MTable.getTables(pattern):
scala> import slick.jdbc.meta.MTable import slick.jdbc.meta.MTable scala> db.withSession { implicit session => MTable.getTables("transactions").list } List[scala.slick.jdbc.meta.MTable] = List(MTable(MQName(fec.transactions),TABLE,,None,None,None) ...)
Thus, to drop the transactions table if it exists, we can run the following:
scala> db.withSession { implicit session => if(MTable.getTables("transactions").list.nonEmpty) ...
Read now
Unlock full access