How do you check if a table exists with slick 3.0?
There was a way in previous versions of slick by using:
MTable.getTables.list()
But this doesn't compile anymore.
The idea behind this question is to dynamically create a table when it doesn't exists, pretty much like this:
if (Tables.contains("USERS") == false)
Users.createTable()
With Slick 3.0 MTable.getTables
is a DBAction
which was to be run via a Database
instance:
val tables = Await.result(db.run(MTable.getTables), 1.seconds).toList
Of course, you should probable deal with the Future
returned by db.run
in an asynchronous manner (via map
or for-comprehension) rather than blocking on it as I did for the example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With