prequel
prequel copied to clipboard
implicit conversion of value contained in an Option container
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: Option[Null] ) extends Nullable( value ) {
override def escaped( formatter: SQLFormatter ): String = "null"
}
object NullFormattable{
def apply( value: Option[Null] ) = new NullFormattable( value )
}
object SQLFormatterImplicits {
implicit def someNull2Formattable( wrapped: Option[Null] ) = NullFormattable( wrapped )
implicit def someInt2Formattable( wrapped: Option[Int] )= wrapped match {
case None => NullFormattable(Some(null))
case Some(value) => IntFormattable(value)
}
implicit def someDouble2Formattable( wrapped: Option[Double] )= wrapped match {
case None => NullFormattable(Some(null))
case Some(value) => DoubleFormattable(value)
}
}
Do you have a better idea ? Could it be added in the master branch ?
there is the Nullable formattable which allows you to have use an Option when formatting. it will result in 'null' in the case of None and otherwise the formatted value.
does this help?
I don't know why but it doesn't work for me wihthout this new definitions. When I try to insert an Option[Int] Scala throws the following error : type mismatch; found: Option[Int] required: net.noerd.prequel.Formattable