How to implement transfers in scala slick 3?

This question has been asked and is responsible for spots 1 and 2, but the answers do not seem valid for spot 3.

Trying to use a template in How to use enumerations in Scala Slick? ,

object MyEnumMapper { val string_enum_mapping:Map[String,MyEnum] = Map( "a" -> MyEnumA, "b" -> MyEnumB, "c" -> MyEnumC ) val enum_string_mapping:Map[MyEnum,String] = string_enum_mapping.map(_.swap) implicit val myEnumStringMapper = MappedTypeMapper.base[MyEnum,String]( e => enum_string_mapping(e), s => string_enum_mapping(s) ) } 

But MappedTypeMapper not available, since slick 1, and the proposed MappedColumnType for slick 2 is no longer available, despite the fact that it is documented here .

What is the latest best practice for this?

+6
source share
1 answer

What exactly do you mean by MappedColumnType is no longer available? It comes with the usual driver import. Matching an enumeration to a string and vice versa using MappedColumnType 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) ) 
+9
source

All Articles