我为我工作的是以下设置:
首先,我的表声明:
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。
希望对你有帮助