检查表格存在于光滑3.0

时间:2023-01-01 16:27:45

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()

1 个解决方案

#1


15  

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.

当然,你应该以异步方式(通过map或for-comprehension)处理db.run返回的Future,而不是像我为这个例子那样阻塞它。

#1


15  

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.

当然,你应该以异步方式(通过map或for-comprehension)处理db.run返回的Future,而不是像我为这个例子那样阻塞它。