sqldelight
sqldelight copied to clipboard
Adding `RETURNING` to an `INSERT` causes existing usages to silently break
Given:
insert:
INSERT INTO People(name)
VALUES (?)
;
and usage as:
val peopleQueries = ...
peopleQueries.insert("Alec")
Change the query to:
insert:
INSERT INTO People(name)
VALUES (?)
+RETURNING id
;
and now your call to insert
still compiles but critically does not execute.
This is a foot gun waiting to happen. Ideally we either fail all compilation sites somehow (@CheckResult
?) or... something else that I can't think of at this time.
(I don't actually think @CheckResult
is a good enough solution)
We can probably do this in the IDE by finding usages and highlighting red if the result isn't used
I'm wondering if we could still make it run synchronously but instead require a lambda which returns R
that ultimately becomes the insert return value.
So
playerQueries.insert("Alec")
before and now after:
val id = playerQueries.insert("Alec") { executeAsOne() }
Since the lambda is required, it would fail to compile on the query change.
maybe, I'm not a huge fan of treating RETURNING
as any different from a normal select in the compiler since as is its a super simple implementation
Yeah I meant this more as a general strategy for one-shot, non-observable queries.
Maybe related #https://github.com/cashapp/sqldelight/issues/3599
What about adding a query method works like Query
but returns R
?
Might be a separate issue entirely, but it seems adding a RETURNING clause to an insert prevents a Flow<> from emitting values.
Might be a separate issue entirely, but it seems adding a RETURNING clause to an insert prevents a Flow<> from emitting values.
This happens for me as well using version 2.0.0-alpha04
. Any update on this? @JakeWharton
No
How to use RETURNING
in 2.0.0 @AlecKazakova