【问题标题】:scala + slick-pg + implicitscala + slick-pg + 隐式
【发布时间】:2015-07-27 16:44:39
【问题描述】:

我尝试根据示例添加列 [slick-pg 示例][1]

也隐含添加到类表中

 implicit val pointFormat = MyFormats.geometryFormat[Point]

但有编译错误

could not find implicit value for parameter tt: slick.ast.TypedType[com.vividsolutions.jts.geom.Point]

我做错了什么?你能举个例子吗? ^

BR!

【问题讨论】:

    标签: scala slick-3.0 slick-pg


    【解决方案1】:

    我为我工作的是以下设置:

    首先,我的表声明:

     class EventTable(tag: Tag) extends Table[Event](tag, "event"){
       def uid = column[String]("uid", O.PrimaryKey, O.Length(36))
       def userUid = column[String]("user_uid")
       def location = column[Point]("location")
       def start = column[LocalDateTime]("start")
       def end = column[LocalDateTime]("end")
       def visible = column[Boolean]("visible")
       def attending = column[Int]("attending")
       def required = column[Int]("required")
       def createdAt = column[LocalDateTime]("created_at")
    
       def * = (uid, userUid, location, start, end, visible, attending, required, createdAt) <>
          (Event.tupled, Event.unapply)
     }
    

    我需要扩展:java8 时间支持 (LocalDateTime) 和地理资料 (Point)。这反映在我的 build.sbt 中 - 我使用 0.11.0 版来制作 slick-pg:

    "com.github.tminglei" %% "slick-pg"                             % slickPgV,
    "com.github.tminglei" %% "slick-pg_jts"                         % slickPgV,
    "com.github.tminglei" %% "slick-pg_date2"                       % slickPgV,
    

    现在,驱动声明:

    import com.github.tminglei.slickpg._
    
    trait ExtendedPostgresDriver extends ExPostgresDriver
      with PgArraySupport
      with PgDate2Support
      with PgRangeSupport
      with PgHStoreSupport
      with PgSearchSupport
      with PgPostGISSupport
      with PgNetSupport
      with PgLTreeSupport {
    
       override val api = MyAPI
    
       object MyAPI extends API with ArrayImplicits
                                with DateTimeImplicits
                                with PostGISImplicits
                                with NetImplicits
                                with LTreeImplicits
                                with RangeImplicits
                                with HStoreImplicits
                                with SearchImplicits
                                with SearchAssistants {
       implicit val strListTypeMapper = new SimpleArrayJdbcType[String]("text").to(_.toList)
    
      }
    }
    
    object ExtendedPostgresDriver extends ExtendedPostgresDriver
    

    所以,拿 Java 8 时间的东西吧。您会注意到驱动程序使用PgDate2Support,然后我可以使用隐式DateTimeImplicits。通过在我感兴趣的类中导入ExtendedPostgresDriver.api._,我可以让表定义使用我需要的LocalDateTime 类型。

    Point 也一样:PgPostGISSupport -> PostGISImplicits -> Point

    希望对你有帮助

    【讨论】:

      【解决方案2】:

      按照this 指令编写与PostgresDriver 的集成时,在覆盖api 的对象中添加with PostGISImplicits(示例中不包含此特征)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-04-09
        • 1970-01-01
        • 2020-12-08
        • 1970-01-01
        • 2016-08-18
        • 1970-01-01
        • 2013-11-01
        相关资源
        最近更新 更多