【发布时间】:2014-04-21 22:57:51
【问题描述】:
我在我的 Scala/Play 应用程序中使用Slick 2 code generator 来生成我的 PostgreSQL 数据库的表类。有些字段虽然是 JSON 类型,但它们会被生成器转换为字符串。我想知道我是否可以以某种方式使用slick-pg plugin 使生成器识别 Postgres JSON 类型?
我尝试将slick.driver.PostgresDriver 直接扩展为Build.scala:
import slick.driver.PostgresDriver
import com.github.tminglei.slickpg._
trait MyPostgresDriver extends PostgresDriver
with PgArraySupport
with PgDateSupport
with PgRangeSupport
with PgHStoreSupport
with PgPlayJsonSupport
with PgSearchSupport
with PgPostGISSupport {
override val Implicit = new ImplicitsPlus {}
override val simple = new SimpleQLPlus {}
trait ImplicitsPlus extends Implicits
with ArrayImplicits
with DateTimeImplicits
with RangeImplicits
with HStoreImplicits
with JsonImplicits
with SearchImplicits
with PostGISImplicits
trait SimpleQLPlus extends SimpleQL
with ImplicitsPlus
with SearchAssistants
with PostGISAssistants
}
object MyPostgresDriver extends MyPostgresDriver
但我不知道如何将它与代码生成器例程而不是标准驱动程序一起使用:
SourceCodeGenerator.main(
Array(
"scala.slick.driver.PostgresDriver", //how do I use MyPostgresDriver here?
"org.postgresql.Driver",
"jdbc:postgresql://localhost:5432/db?user=root&password=root",
"app",
"db"
)
)
【问题讨论】:
标签: json postgresql scala playframework slick