initmax
initmax

Reputation: 395

scala + slick-pg + implicit

I tried to add column based on example [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!

Upvotes: 1

Views: 1327

Answers (2)

Radu
Radu

Reputation: 1104

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). This is reflected in my build.sbt - I use version 0.11.0 for slick-pg:

"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. You can notice that the driver uses PgDate2Support, which then allows me the usage of the implicit 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.

Same thing for Point: PgPostGISSupport -> PostGISImplicits -> Point.

Hope this helps

Upvotes: 1

Decly
Decly

Reputation: 379

When writing the integration with the PostgresDriver following this instructions add with PostGISImplicits in the object that overrides api (this trait is not included in the example).

Upvotes: 0

Related Questions