[英]scala + slick-pg + implicit
I tried to add column based on example [slick-pg example][1] 我尝试根据示例[slick-pg example] [1]添加列
Also added to the class table implicite 还添加到类表的隐式
implicit val pointFormat = MyFormats.geometryFormat[Point]
but have a compile error 但是有一个编译错误
could not find implicit value for parameter tt: slick.ast.TypedType[com.vividsolutions.jts.geom.Point]
What I have done wrong? 我做错了什么? could you please give work example ? 你能举个工作的例子吗? ^ ^
BR! BR!
What I have working for me is something in the following setup: 我为我工作的是以下设置中的内容:
First, my table declaration: 首先,我的表声明:
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)
}
I need to extensions: java8 time support (LocalDateTime) and geo stuff (Point). 我需要扩展:java8时间支持(LocalDateTime)和地理对象(Point)。 This is reflected in my build.sbt
- I use version 0.11.0 for slick-pg: 这反映在我的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,
Now, the driver declaration: 现在,驱动程序声明:
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
So, take the java 8 time stuff. 因此,请使用Java 8时间工具。 You can notice that the driver uses PgDate2Support
, which then allows me the usage of the implicit DateTimeImplicits
. 您会注意到驱动程序使用PgDate2Support
,然后允许我使用隐式DateTimeImplicits
。 By importing the ExtendedPostgresDriver.api._
in my class of interest, I can then have the table definition use the LocalDateTime
type that I need. 通过在我感兴趣的类中导入ExtendedPostgresDriver.api._
,我可以使表定义使用所需的LocalDateTime
类型。
Same thing for Point
: PgPostGISSupport
-> PostGISImplicits
-> Point
. 对Point
: PgPostGISSupport
> PostGISImplicits
> Point
。
Hope this helps 希望这可以帮助
当与PostgresDriver编写集成以下这说明添加with PostGISImplicits
在覆盖对象api
(不包括在本例中这个特质)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.