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

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

概述我在我的 Scala / Play应用程序中使用 Slick 2 code generator来生成PostgreSQL数据库的表类.有些字段是JSON类型,它们由生成器转换为String.我想知道我是否能以某种方式使用 slick-pg plugin使发生器识别Postgres JSON类型? 我试图直接在Build.scala中扩展slick.driver.PostgresDriver: im 我在我的 Scala / Play应用程序中使用 Slick 2 code generator来生成Postgresql数据库的表类.有些字段是JsON类型,它们由生成器转换为String.我想知道我是否能以某种方式使用 slick-pg plugin使发生器识别Postgres JsON类型?

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

import slick.driver.PostgresDriverimport 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

总结

以上是内存溢出为你收集整理的使用带有Slick 2代码生成器的PostgreSQL JSON类型全部内容,希望文章能够帮你解决使用带有Slick 2代码生成器的PostgreSQL JSON类型所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/1181524.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-02
下一篇2022-06-02

发表评论

登录后才能评论

评论列表(0条)

    保存