How to implement enums in scala slick 3? How to implement enums in scala slick 3? database database

How to implement enums in scala slick 3?


What exactly do you mean by MappedColumnType is no longer available? It comes with the usual import of the driver. Mapping an enum to a string and vice versa using MappedColumnType is pretty straight forward:

object MyEnum extends Enumeration {  type MyEnum = Value  val A = Value("a")  val B = Value("b")  val C = Value("c")}implicit val myEnumMapper = MappedColumnType.base[MyEnum, String](  e => e.toString,  s => MyEnum.withName(s))


A shorter answer so that you don't need to implement myEnumMapper yourself:

import play.api.libs.json.{Reads, Writes}object MyEnum extends Enumeration {  type MyEnum = Value  val A, B, C = Value // if you want to use a,b,c instead, feel free to do it  implicit val readsMyEnum = Reads.enumNameReads(MyEnum)  implicit val writesMyEnum = Writes.enumNameWrites}