jpersson/prequel — Issue #6: implicit conversion of value contained in an Option container
Author: crumbpicker
Created: 2012-02-01 13:49:39+00:00
State: open

The SQLFormatterImplicits doesn't provide a support for values encapsulated in an Option.
Here is the workaround I'm currently using :

import net.noerd.prequel.Nullable
import net.noerd.prequel.IntFormattable
import net.noerd.prequel.DoubleFormattable
import net.noerd.prequel.SQLFormatter

class NullFormattable( override val value: Null ) extends Nullable( null ) {
override def escaped( formatter: SQLFormatter ): String = "null"
}
object NullFormattable{
def apply( value: Null ) = new NullFormattable( null )
}

object SQLFormatterImplicits {
implicit def someInt2Formattable( wrapped: Option[Int] )= wrapped match {
case None => NullFormattable(null)
case Some(value) => IntFormattable(value)
}
implicit def someDouble2Formattable( wrapped: Option[Double] )= wrapped match {
case None => NullFormattable(null)
case Some(value) => DoubleFormattable(value)
}
}

Do you have a better idea ?
Could it be added in the master branch ?