Closed mike-miroliubov closed 3 days ago
🤔 Problem is here (data class tuple insert) where the ?
is hardcoded https://github.com/cashapp/sqldelight/blob/6aa2924c49dff814e1d4f757e15d723848969724/sqldelight-compiler/src/main/kotlin/app/cash/sqldelight/core/lang/util/TreeUtil.kt#L195
🪄 The code from here (single parameter insert) is needed to determine if the async bind param is generated
https://github.com/cashapp/sqldelight/blob/6aa2924c49dff814e1d4f757e15d723848969724/sqldelight-compiler/src/main/kotlin/app/cash/sqldelight/core/compiler/QueryGenerator.kt#L222
🌳 Somehow TreeUtil will need to know that async generation is being used and the bind parameters are indexed
e.g in PsiElement.rangesToReplace()
do something like ...
val generateAsync = this.sqFile().generateAsync
val bindExpr = childOfType(SqlTypes.BIND_EXPR) as SqlBindExpr
val bindParameterMixin = bindExpr.bindParameter as BindParameterMixin
buildList {
if (parent!!.columnNameList.isEmpty()) {
add(
Pair(
first = parent!!.tableName.range,
second = parent!!.columns.joinToString(
separator = ", ",
prefix = "${parent!!.tableName.text} (",
postfix = ")",
) { it.name },
),
)
}
add(
Pair(
first = childOfType(SqlTypes.BIND_EXPR)!!.range,
second = (1..parent!!.columns.size).joinToString(separator = ", ", prefix = "(", postfix = ")") { bindParameterMixin.replaceWith(generateAsync, it) },
),
)
SQLDelight Version
2.0.2
Operating System
MacOS
Gradle Version
8.5
Kotlin Version
2.0.0
Dialect
postgresql-dialect
AGP Version
No response
Describe the Bug
Thanks for a great library! I've noticed a bug in the generated queries code when using R2DBC: incorrect parameters syntax is used when a query has tuple object substitution.
Example:
This generates code:
But R2DBC uses
$1
...1N
parameter syntax and this code throws an exception:However, when a query has individual field parameters:
The generated code is correct:
Stacktrace
Gradle Build Script