Skip to content

Commit

Permalink
Fixed nullable plain params
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagocordeiro committed Sep 9, 2024
1 parent 846d287 commit b9d03fe
Show file tree
Hide file tree
Showing 11 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/io/tcds/orm/Param.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ interface Param<T> {
val value: T

fun bind(stmt: PreparedStatement, index: Int)
fun plain(): Any = value as Any
fun plain(): Any? = value
fun describe(): String = "$name=$value"
}
1 change: 0 additions & 1 deletion src/main/kotlin/io/tcds/orm/param/BooleanParam.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ data class BooleanParam(
override val name: String,
override val value: Boolean,
) : Param<Boolean> {
override fun plain(): Boolean = value
override fun bind(stmt: PreparedStatement, index: Int) = stmt.setBoolean(index, value)
}
1 change: 0 additions & 1 deletion src/main/kotlin/io/tcds/orm/param/ColumnParam.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ data class ColumnParam<Entry, Type>(
override val value: Type,
) : Param<Type> {
override val name: String = column.name
override fun plain(): Any = value as Any
override fun bind(stmt: PreparedStatement, index: Int) = column.bind(stmt, index, value)
}
1 change: 0 additions & 1 deletion src/main/kotlin/io/tcds/orm/param/DoubleParam.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ data class DoubleParam(
override val name: String,
override val value: Double,
) : Param<Double> {
override fun plain(): Double = value
override fun bind(stmt: PreparedStatement, index: Int) = stmt.setDouble(index, value)
}
1 change: 0 additions & 1 deletion src/main/kotlin/io/tcds/orm/param/FloatParam.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ data class FloatParam(
override val name: String,
override val value: Float,
) : Param<Float> {
override fun plain(): Float = value
override fun bind(stmt: PreparedStatement, index: Int) = stmt.setFloat(index, value)
}
1 change: 0 additions & 1 deletion src/main/kotlin/io/tcds/orm/param/IntegerParam.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ data class IntegerParam(
override val name: String,
override val value: Int,
) : Param<Int> {
override fun plain(): Int = value
override fun bind(stmt: PreparedStatement, index: Int) = stmt.setInt(index, value)
}
1 change: 0 additions & 1 deletion src/main/kotlin/io/tcds/orm/param/LongParam.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ data class LongParam(
override val name: String,
override val value: Long,
) : Param<Long> {
override fun plain(): Long = value
override fun bind(stmt: PreparedStatement, index: Int) = stmt.setLong(index, value)
}
1 change: 0 additions & 1 deletion src/main/kotlin/io/tcds/orm/param/StringParam.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ data class StringParam(
override val name: String,
override val value: String,
) : Param<String> {
override fun plain(): String = value
override fun bind(stmt: PreparedStatement, index: Int) = stmt.setString(index, value)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ data class NullableEnumParam<T : Enum<*>>(
override val name: String,
override val value: T?,
) : Param<T?> {
override fun plain(): Any? = value?.name
override fun bind(stmt: PreparedStatement, index: Int) = when (value) {
null -> stmt.setNull(index, Types.VARCHAR)
else -> stmt.setString(index, value.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ data class NullableInstantParam(
override val name: String,
override val value: Instant?,
) : Param<Instant?> {
override fun plain(): String? = value?.toString()
override fun bind(stmt: PreparedStatement, index: Int) = when (value) {
null -> stmt.setNull(index, Types.TIMESTAMP)
else -> stmt.setTimestamp(index, Timestamp.from(value))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ data class NullableJsonParam<T>(
override val name: String,
override val value: T?,
) : Param<T?> {
override fun plain(): String? = value?.let { JsonParam.mapper.writeValueAsString(it) }
override fun bind(stmt: PreparedStatement, index: Int) = when (value) {
null -> stmt.setNull(index, Types.VARCHAR)
else -> stmt.setString(index, JsonParam.mapper.writeValueAsString(value))
Expand Down

0 comments on commit b9d03fe

Please sign in to comment.