-
Notifications
You must be signed in to change notification settings - Fork 540
Infer the Kotlin type of bind parameter, if possible, or fail with a … #3413
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
Conversation
…better error message
This might also fix the following, right? CREATE TABLE directory (
id TEXT NOT NULL PRIMARY KEY,
refreshOnStartUp INTEGER AS Boolean
);
CREATE TABLE channel (
id TEXT NOT NULL PRIMARY KEY,
refreshOnStartUp INTEGER AS Boolean,
directoryId TEXT
);
myQuery:
SELECT channel.*
FROM channel
LEFT JOIN directory
ON channel.directoryId = directory.id
WHERE COALESCE(channel.refreshOnStartUp, directory.refreshOnStartUp, :refreshOnStartUp) = 1
; Currently, I'm getting:
|
@vanniktech Nope, because coalesce supports many different sql types: But you will get a better error message indicating you to use CAST :D |
Alright, I ended up casting now anyways. Would not it still be possible to infer the type? Both Also, I can't seem to write
I need to use |
Maybe it is possible to infer the kotlin type with multiple possible sql types too, when the corresponding sql type have the same kotlin representation, eg tiny int uses Int/Long not Short etc Update: They do use different Kotlin types |
@vanniktech Yes, it must be valid SQL, not sqldelight AS Kotlin
Sounds possible, but I would also emit a warning
|
Why the warning? You can see the return type in the generated code. |
Okay, that's true :D I'd just prevent wrong questions a la "my Kotlin type is wrong" because people forget CAST, including me |
Created #3416 for this |
…better error message
Fixes #3407 with a better error message
The compiler can now infer the Kotlin type of a bind parameter, if
encapsulatingType
has exactly 1 sql type. This is used forCONCAT
: eg https://github.com/cashapp/sqldelight/blob/02edf13f390229d3eb8986b5c408fd795a085e0f/dialects/mysql/src/main/kotlin/app/cash/sqldelight/dialects/mysql/MySqlTypeResolver.kt#L55