微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用带有Slick 2代码生成器的PostgreSQL JSON类型

我在我的 Scala / Play应用程序中使用 Slick 2 code generator生成Postgresql数据库的表类.有些字段是JSON类型,它们由生成器转换为String.我想知道我是否能以某种方式使用 slick-pg plugin使发生器识别Postgres JSON类型?

我试图直接在Build.scala中扩展slick.driver.PostgresDriver:

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"
    )
)
你不能让发电机以这种方式拾取类型.它(或者更确切地说是从数据库模式中反向设计模型的Slick代码)当前只检测到一个充满类型的手,并简单地假定所有其他类型的String.这将在未来得到改善.为了使它对列使用不同的类型,您必须自定义生成器.相应的Slick文档示例实际上显示了如何自定义类型:

http://slick.typesafe.com/doc/2.0.0/code-generation.html#customization

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐