简体   繁体   English

检查表格存在于光滑3.0

[英]Check table existence in slick 3.0

How do you check if a table exists with slick 3.0? 如何检查表格是否存在光滑的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: 使用Slick 3.0 MTable.getTables是一个DBAction ,它将通过Database实例运行:

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. 当然,你可能要应对的Future返回由db.run以异步方式(通过map 或-理解 ),而不是阻止它像我一样的例子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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