什么是 DBIO 以及如何获取底层对象?

What's DBIO and how can I get the underlying object?

在使用 Slick 3.0.3 和尝试解决这个问题的背景下 我得到的结果是:

import slick.dbio.DBIO
import slick.model.Model
import slick.driver.PostgresDriver
import slick.jdbc.meta.MTable
import slick.codegen.SourceCodeGenerator

val model : DBIO[Model] = PostgresDriver.createModel(Some(MTable.getTables(None, None, None, Some(Seq("table1","table2","view1")))))
// SourceCodeGenerator requires a Model and not a DBIO[Model]
val codegen = new SourceCodeGenerator(model)

看起来差不多了,但是 PostgresDriver.createModel returns 是 DBIO[Model] 而不是 Model 我不知道如何提取模型或其他运行 具有此类模型参考的生成器。这个 DBIO 到底是什么?

DBIODBIOAction 的一种。 DBIOAction 是可以对数据库执行的操作。但是还没有在数据库上执行。您需要创建到数据库的连接以获取数据库对象,并将 DBIO[Model] 对象传递给它,应该 return 一个 Future[Model].

编辑:

有关创建数据库对象的信息,请参阅:http://slick.typesafe.com/doc/3.0.2/gettingstarted.html

您需要在 application.conf 中进行正确的配置。然后,您可以使用如下代码:

val db = Database.forConfig("h2mem1")
    val dbio = PostgresDriver.createModel(Some(MTable.getTables(None, None, None, Some(Seq("table1","table2","view1")))))
    val modelF = db.run(dbio) //Produces Future[Model]
    val genF = modelF.map(model => new SourceCodeGenerator(model)) //Produces Future[SourceCodeGenerator]