If the column is successfully parsed, then apply the given function on the result.
If the column is successfully parsed, then apply the given function on the result.
import anorm.{ Column, SqlParser, SQL } sealed trait MyEnum case object Foo extends MyEnum case object Bar extends MyEnum val myEnumCol: Column[MyEnum] = Column.of[Int].map { case 1 => Right(Foo) // `Right` means successful case 2 => Right(Bar) } def find(id: String) = SQL"SELECT enum_code FROM my_table WHERE id = $id". as(SqlParser.scalar(myEnumCol).single)
If the column is successfully parsed, then apply the given function on the result.
If the column is successfully parsed, then apply the given function on the result.
import anorm.{ Column, SqlParser, SQL } sealed trait MyEnum case object Foo extends MyEnum case object Bar extends MyEnum val myEnumCol: Column[MyEnum] = Column.of[Int].mapResult { case 1 => Right(Foo) // `Right` means successful case 2 => Right(Bar) case _ => Left(SqlMappingError("Unexpected")) } def find(id: String) = SQL"SELECT enum_code FROM my_table WHERE id = $id". as(SqlParser.scalar(myEnumCol).single)
Column mapping