1

我尝试根据示例添加列 [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!

4

2 回答 2

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- 我为 slick-pg 使用 0.11.0 版本:

"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

希望这可以帮助

于 2016-01-31T19:40:18.667 回答
0

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

于 2016-01-17T16:13:04.970 回答