-
Notifications
You must be signed in to change notification settings - Fork 510
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 adapter with question mark only #3314
Conversation
val argumentAdapters = PsiTreeUtil.findChildrenOfType(this, SqlBindExpr::class.java) | ||
.mapNotNull { typeResolver.argumentType(it).parentAdapter() } | ||
val binders = PsiTreeUtil.findChildrenOfType(this, SqlBindExpr::class.java) | ||
val argumentAdapters = binders.singleQuestionMark() ?: binders.mapNotNull { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this only works if theres only a single question mark in the whole file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, added a test with two insert statements
.mapNotNull { typeResolver.argumentType(it).parentAdapter() } | ||
val binders = PsiTreeUtil.findChildrenOfType(this, SqlBindExpr::class.java) | ||
val argumentAdapters = binders.singleQuestionMark() ?: binders.mapNotNull { | ||
typeResolver.argumentType(it).parentAdapter() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you'll want to have your logic live in this function and have it be invoked as a flatMap
so that you can expand a single SqlBindExpr
to multiple PropertySpec
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and the logic would be
.flatMap {
it.parentOfType<SqlInsertStmt>()?.let {
if (it.acceptsTableInterface()) return@flatMap listOf(table.adapterProperty())
}
return listOf(typeResolver.argumentType(it).parentAdapter())
}.filterNotNull()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, but don't you need if (it.acceptsTableInterface() && it.needsAdapter())
to prevent adding unused and unnecessary adapter property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah right, because the table has only one adapter not multiple. Yes
sqldelight-compiler/src/main/kotlin/app/cash/sqldelight/core/lang/SqlDelightQueriesFile.kt
Outdated
Show resolved
Hide resolved
…ang/SqlDelightQueriesFile.kt
Fixes #3233
Rather a hack, but works...