Skip to content

Instantly share code, notes, and snippets.

@devshorts
Created February 23, 2018 02:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devshorts/6d1bb71c08578b904ea02dd38141af03 to your computer and use it in GitHub Desktop.
Save devshorts/6d1bb71c08578b904ea02dd38141af03 to your computer and use it in GitHub Desktop.
trait BigIntegerTypesComponent extends RelationalTypesComponent {
self: JdbcProfile =>
implicit def bigIntType = new BigIntegerJdbcType
implicit val bigIntSetParam = new SetParameter[BigInteger] {
override def apply(v1: BigInteger, v2: PositionedParameters): Unit = v2.setObject(v1, java.sql.Types.BIGINT)
}
class BigIntegerJdbcType extends DriverJdbcType[BigInteger] with NumericTypedType {
def sqlType = java.sql.Types.BIGINT
def setValue(v: BigInteger, p: PreparedStatement, idx: Int) = {
p.setObject(idx, v)
}
def getValue(r: ResultSet, idx: Int): BigInteger = {
val v = r.getObject(idx)
if (v eq null) {
null
} else {
v match {
case l: java.lang.Long =>
BigInteger.valueOf(l)
case _ =>
v.asInstanceOf[BigInteger]
}
}
}
def updateValue(v: BigInteger, r: ResultSet, idx: Int) = {
r.updateObject(idx, v)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment