doobie.enum.columnnullable.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of doobie-core-cats_2.11 Show documentation
Show all versions of doobie-core-cats_2.11 Show documentation
Pure functional JDBC layer for Scala.
The newest version!
package doobie.enum
import doobie.util.invariant._
import doobie.enum.{ nullability => N }
import java.sql.ResultSetMetaData._
import cats.kernel.Eq
import cats.kernel.instances.int._
object columnnullable {
/** @group Implementation */
sealed abstract class ColumnNullable(val toInt: Int) {
def toNullability: N.Nullability =
N.Nullability.fromColumnNullable(this)
}
/** @group Values */ case object NoNulls extends ColumnNullable(columnNoNulls)
/** @group Values */ case object Nullable extends ColumnNullable(columnNullable)
/** @group Values */ case object NullableUnknown extends ColumnNullable(columnNullableUnknown)
/** @group Implementation */
object ColumnNullable {
def fromInt(n:Int): Option[ColumnNullable] =
Some(n) collect {
case NoNulls.toInt => NoNulls
case Nullable.toInt => Nullable
case NullableUnknown.toInt => NullableUnknown
}
def fromNullability(n: N.Nullability): ColumnNullable =
n match {
case N.NoNulls => NoNulls
case N.Nullable => Nullable
case N.NullableUnknown => NullableUnknown
}
def unsafeFromInt(n: Int): ColumnNullable =
fromInt(n).getOrElse(throw InvalidOrdinal[ColumnNullable](n))
implicit val EqColumnNullable: Eq[ColumnNullable] =
Eq.by(_.toInt)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy