1
votes

My use case is very simple.

I have wrapper class around string in scala and I want to map it to String type in database using my custom scala mapper code (class is 3rd party and I can't modify it.

All examples I found so far referring to MappedColumnType which does not seems to exist in Slick 3.

Any help and ideally working examples are appreciated.

1
it seems MappedColumnType is indeed supported in slick 3. slick.lightbend.com/doc/3.0.0/userdefined.html - rogue-one
For some reason I do not see it in my classpath. Let me double check my sbt config. - Petro Semeniuk

1 Answers

0
votes

Looks like you might be missing the driver api import!

For some reference, have a look at my example here:

https://github.com/joesan/plant-simulator/blob/master/app/com/inland24/plantsim/services/database/DBSchema.scala

implicit def powerPlantTypeMapping =
    MappedColumnType.base[PowerPlantType, String](
      powerPlantType => PowerPlantType.toString(powerPlantType),
      powerPlantTypeStr => PowerPlantType.fromString(powerPlantTypeStr)
    )

You need to import:

import driver.api._