加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-13 18:06:35 所属栏目:百科 来源:网络整理
导读:我在我的 Scala / Play应用程序中使用 Slick 2 code generator来生成PostgreSQL数据库的表类.有些字段是JSON类型,它们由生成器转换为String.我想知道我是否能以某种方式使用 slick-pg plugin使发生器识别Postgres JSON类型? 我试图直接在Build.scala中扩展s
我在我的 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读