0
votes

I would like to define a new Column/converter to marshal a case class to a primitive type and back again using phantom dsl.

in slick 3.1.1 I can do this easily:

  implicit val idTypeMapper = MappedColumnType.base[Id, Long](
    { (v) ⇒ v.value },
    { (s) ⇒ Id(s) }
  )

This allows me to use the Id anywhere in a slick query and it will be implicitly converted back and forth.

I have tried to derive my own Columns and conversions in phantom by extending AbstractColumn (and other) but with no luck.

How do I do this in phantom dsl.

1

1 Answers

0
votes

With apologies for the late reply, you would simply use Primitive.derive. More details on the official docs.

import com.outworkers.phantom.dsl._

case class Test(value: String)

object Test {
  implicit val testPrimitive: Primitive[Test] = {
    Primitive.derive[Test, String](_.value)(Test.apply)
  }
}