dave08
10/29/2024, 9:13 AMunnest(/*listParam*/::int[])
?Toshihiro Nakamura
10/29/2024, 10:09 AMunnest(?::int[])
dave08
10/29/2024, 10:13 AMdave08
10/29/2024, 10:15 AM@JvmInline
value class CastedIntList(val list: String) {
constructor(list: List<Int>) : this(
list.joinToString(separator = ",")
)
constructor(vararg values: Int) : this(
values.joinToString(separator = ",")
)
val size: Int get() = list.split(",").size
}
And the template still removed the ::int[] cast and gave me: unnest('1,2,3')...dave08
10/29/2024, 10:18 AM/*list.list*/1::int[]
(which is probably wrong anyways)... when I did: /*list.list*/'1'::int[]
it worked! But it would still be nice to not have to make that value class for this....dave08
10/29/2024, 10:59 AMdave08
10/29/2024, 11:01 AMToshihiro Nakamura
10/29/2024, 11:20 AMdryRun
calls R2dbcDataType.toString
for each bound value. Link to the code
If you want to customize the toString
result, you might consider creating a user-defined data type. Documentation on user-defined data typesdave08
10/29/2024, 11:31 AMsql
and args
instead of sqlWithArgs
...dave08
10/29/2024, 12:15 PMval result = QueryDsl.execute(AddSongsToPlaylist(
1,
listOf(1, 2, 3)
)).dryRun(dbConfig)
expectThat(result.args).isEqualTo(listOf(
Value(1, typeOf<Int>()),
Value(3, typeOf<Int>()),
Value(1, typeOf<Int>()),
Value(listOf(1, 2, 3), typeOf<List<Int>>()),
Value(1, typeOf<Int>()),
))
is failing, I'm getting a Value for each element in the list instead...dave08
10/29/2024, 12:16 PMdave08
10/29/2024, 12:17 PMdave08
10/29/2024, 12:20 PMDryRunStatement
does return the list and not the individual values and I don't need to worry?dave08
10/29/2024, 12:21 PMprivate suspend fun queryResult(context: TemplateSelectContext): QueryResult {
val runner = TemplateSelectRunner(context)
val stmt = runner.dryRun(config)
val result = try {
if (stmt.args.isEmpty())
conn.sendQuery(stmt.sql)
else
conn.sendPreparedStatement(
stmt.sql,
stmt.args.map { it.any }
)
} catch (e: Exception) {
logger.error { "Error running: ${context.sql} with params: ${context.printArgs()}" }
throw e
}
return result
}
dave08
10/29/2024, 12:22 PMJasyncQueryVisitor
Toshihiro Nakamura
10/29/2024, 12:24 PMDryRunResult.args
returns the bound values. For example, if you bind a List, it returns the List itself, not the individual elements within it.Toshihiro Nakamura
10/29/2024, 12:53 PMdave08
10/29/2024, 12:56 PMdave08
10/29/2024, 12:59 PMIN (?, ?, ?...)
in the sql?Toshihiro Nakamura
10/29/2024, 1:02 PM?, ?, ?
dave08
10/29/2024, 1:10 PMDryRunStatement
I get separate Value's for each entry... unless this only happens in DryRunResult?Toshihiro Nakamura
10/29/2024, 3:13 PMDryRunResult.args
.
unless this only happens in DryRunResult?No, this behavior is the same even without using
DryRunResult
.dave08
10/29/2024, 3:15 PMToshihiro Nakamura
10/29/2024, 3:20 PMIterable
are given special treatment during binding.Toshihiro Nakamura
10/29/2024, 3:23 PMValue
classes are also given special treatment, with their internal types being used.
See also https://github.com/komapper/komapper/blob/v3.1.0/komapper-template/src/main/kotlin/org/komapper/template/TwoWayTemplateStatementBuilder.kt#L122-L167dave08
10/29/2024, 3:28 PM