Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: EXPOSED-501 Column.transform() ignores custom setParameter() logic #2214

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions exposed-core/api/exposed-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ public class org/jetbrains/exposed/sql/ColumnWithTransform : org/jetbrains/expos
public fun nonNullValueToString (Ljava/lang/Object;)Ljava/lang/String;
public fun notNullValueToDB (Ljava/lang/Object;)Ljava/lang/Object;
public fun setNullable (Z)V
public fun setParameter (Lorg/jetbrains/exposed/sql/statements/api/PreparedStatementApi;ILjava/lang/Object;)V
public fun sqlType ()Ljava/lang/String;
public fun unwrap (Ljava/lang/Object;)Ljava/lang/Object;
public final fun unwrapRecursive (Ljava/lang/Object;)Ljava/lang/Object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ open class ColumnWithTransform<Unwrapped : Any, Wrapped : Any>(
}

override var nullable = delegate.nullable

override fun setParameter(stmt: PreparedStatementApi, index: Int, value: Any?) {
return delegate.setParameter(stmt, index, value)
}
}

// Numeric columns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,4 +406,23 @@ class JsonColumnTests : DatabaseTestsBase() {
assertEquals(newData2, newResult?.get(tester.jsonColumn))
}
}

@Test
fun testJsonWithTransformer() {
val tester = object : Table("tester") {
val numbers: Column<DoubleArray> = json<IntArray>("numbers", Json.Default).transform(
wrap = { DoubleArray(it.size) { i -> 1.0 * it[i] } },
unwrap = { IntArray(it.size) { i -> it[i].toInt() } }
)
}

withTables(tester) {
val data = doubleArrayOf(1.0, 2.0, 3.0)
tester.insert {
it[numbers] = data
}

assertContentEquals(data, tester.selectAll().single()[tester.numbers])
}
}
}
Loading