-
Notifications
You must be signed in to change notification settings - Fork 540
Notify queries when executing group statements with result #5006
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
Any updates on this? |
Hello! We have migrated to SQLDelight following the Realm deprecation, but this is a major issue for us. This bug makes it much more complex to build a reactive app that responds to upserted data. We have many nested relationships in our data and using the SQLite upsert makes it easy to establish these relationships using the returned row ID while hiding whether a new row was added or an existing row updated (since it doesn't actually matter for most of our app). To get live updates to the DB data without this bug fixed, we will have to explicitly query a row, check if it's null, call an insert query if missing and then grab the last inserted rowid via another query; and if it's not null, grab the existing key and perform an update query instead for every single entity relationship we have. Being able to return the inserted/updated key hides this complexity from the app and keeps DB operations neatly in the SQL. Any updates on this PR would be really appreciated! |
I think this approach makes sense to me.
This isn't something we need to be concerned about. Kotlinpoet will output what it outputs, it doesn't need to be pretty-printed.
The Query ID is a hash based on the name of the query and is stable between runs. Getting it from the compiler is "ideal" in the sense that if we were to ever change the way these values were hashed, we wouldn't need to go through and update dozens of tests. In this case, you can just get it from The query ID refers to the whole grouped query and is used to help dedupe notifications in transactions where the grouped query could be invoked multiple times, so there's no extra work needed to isolate it to one or either of the statements. |
If we can get this rebased and the tests fixed up, I think this is ready to merge 👍 |
The space is because control flow is the wrong mechanism to use. But it's good enough for now, and produces close enough output. |
Rebased. Also replaced with hardcoded IDs with |
Fixes:
INSERT INTO ...VALUES(...) RETURNING id;
not working with coroutines flow #4975Proposed solution
By modifying the
QueryGenerator
to make sure all child classes have access totablesUpdated()
, and centralising the query notification into theexecuteBlock
function, make sure the following is added to the generated code of grouped statements.I am not completely sure of this approach and I'd love some feedback before I dedicate more time into it.
To be solved yet
Annoying space before
.also {
. I'll learn a bit more of Kotlinpoet :)Questions
notifyQueriesBlock()
to accept the QueryId and make it match one of the statements.Remark
I am not sure about the
executeBlock
. I find its control flow a bit hard to follow and I'd love to simplify a bit and maybe link theQueryGenerator
's implementations more closely to implement it depending on what the query looks like, instead of having too many ifs and elses.