Question

I'm new to scala and slick and am having a bit of trouble.

I am trying to implement a custom type mapper that supports nulls.

This example is straightforward...

http://slick.typesafe.com/doc/2.0.0/userdefined.html

I'm looking for an example where the column can defined as [Option[MyColumnT]]

I thought I could do something like this

implicit val oAuth1InfoColumnType = MappedColumnType.base[Option[OAuth1Info], Option[String]](
    {
        case Some(info) => {
            val skv = new SKV("token", info.token)
            skv.append("secret", info.secret)
            Some(skv.toString)
        }
        case None => None
    },{
        case Some(infoStr) => {
            val skv = new SKV(infoStr)
            Some(OAuth1Info(skv("token"), skv("secret")))
        }
        case None => None
    }
)
def oAuth1Info = column[Option[OAuth1Info]]("oauth1_info")

However, this results in an error.

[error] could not find implicit value for evidence
parameter of type slick.driver.PostgresDriver.BaseColumnType[Option[String]]

Obviously I'm not understanding whether or not it's my responsibility to deal with the nulls vs. just providing an implicit type mapper as [MyColumnT, String] without Option. So, I'm looking for an example.

Was it helpful?

Solution

Option support should work out of the box. Just define a MappedColumnType.base[OAuth1Info, String] and use it: column[Option[OAuth1Info]](...).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top