Skip to content

Commit

Permalink
Update TypeMapper.scala added support for Float data type (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmorales-iaa authored Sep 26, 2024
1 parent a48a4aa commit 3eab45e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions scalasql/core/src/DialectTypeMappers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ trait DialectTypeMappers extends DialectConfig {
implicit def IntType: TypeMapper[Int]
implicit def LongType: TypeMapper[Long]

implicit def FloatType: TypeMapper[Float]
implicit def DoubleType: TypeMapper[Double]
implicit def BigDecimalType: TypeMapper[scala.math.BigDecimal]
implicit def BooleanType: TypeMapper[Boolean]
Expand Down
3 changes: 2 additions & 1 deletion scalasql/core/src/TypeMapper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ object TypeMapper {
d.IntType
implicit def longFromDialectTypeMappers(implicit d: DialectTypeMappers): TypeMapper[Long] =
d.LongType

implicit def floatFromDialectTypeMappers(implicit d: DialectTypeMappers): TypeMapper[Float] =
d.FloatType
implicit def doubleFromDialectTypeMappers(implicit d: DialectTypeMappers): TypeMapper[Double] =
d.DoubleType
implicit def bigDecimalFromDialectTypeMappers(
Expand Down
13 changes: 13 additions & 0 deletions scalasql/src/dialects/Dialect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ trait Dialect extends DialectTypeMappers {
def put(r: PreparedStatement, idx: Int, v: Long) = r.setLong(idx, v)
}

implicit def FloatType: TypeMapper[Float] = new FloatType
class FloatType extends TypeMapper[Float] {
def jdbcType = JDBCType.FLOAT
def get(r: ResultSet, idx: Int) = r.getFloat(idx)
def put(r: PreparedStatement, idx: Int, v: Float) = r.setFloat(idx, v)
}

implicit def DoubleType: TypeMapper[Double] = new DoubleType
class DoubleType extends TypeMapper[Double] {
def jdbcType = JDBCType.DOUBLE
Expand Down Expand Up @@ -197,12 +204,18 @@ trait Dialect extends DialectTypeMappers {
def put(r: PreparedStatement, idx: Int, v: T) = r.setObject(idx, v, java.sql.Types.OTHER)
}

implicit def from(x: Byte): Expr[Byte] = Expr(x)

implicit def from(x: Short): Expr[Short] = Expr(x)

implicit def from(x: Int): Expr[Int] = Expr(x)

implicit def from(x: Long): Expr[Long] = Expr(x)

implicit def from(x: Boolean): Expr[Boolean] = Expr.apply0(x, x)

implicit def from(x: Float): Expr[Float] = Expr(x)

implicit def from(x: Double): Expr[Double] = Expr(x)

implicit def from(x: scala.math.BigDecimal): Expr[scala.math.BigDecimal] = Expr(x)
Expand Down

0 comments on commit 3eab45e

Please sign in to comment.