0

While using Slick 3.0.3 and in the context of trying to solve this question how-to-use-slick-code-generator-to-include-database-views-as-well I get as far as this:

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)

It looks almost there, however PostgresDriver.createModel returns a DBIO[Model] and not a Model and I don't see how to extract the model or for that matter run the generator with such model reference. What's this DBIO anyway?

Community
  • 1
  • 1
SkyWalker
  • 13,729
  • 18
  • 91
  • 187

1 Answers1

2

DBIO is a type of DBIOAction. A DBIOAction is an action that can be taken on the database. But it has not been executed on the database yet. You need to create a connection to your database to get a database object, and pass the DBIO[Model] object to it, which should return a Future[Model].

EDIT:

For info on creating a database object, see: http://slick.typesafe.com/doc/3.0.2/gettingstarted.html

You need to have the right config in application.conf. Then, you can use code such as:

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]
mattinbits
  • 10,370
  • 1
  • 26
  • 35