简体   繁体   中英

Check table existence in slick 3.0

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM