synw / sqlcool

Easy and reactive Sqlite for Flutter
MIT License
163 stars 28 forks source link

Problem with db.query and reactive update #21

Open ederluca opened 4 years ago

ederluca commented 4 years ago

I was observing a problem in updating the data using reactive, when you for example execute the command db.query () and for example execute an update I realized that the stream process is not updated, however if I use db.update the update occurs I do not know if it would be a bug or if this is really the behavior.

synw commented 4 years ago

Right. The thing is that query is just a string, and the function is not aware of what kind of operation it is, neither or the table and the data impacted. Therefore we can not provide the changefeed with the proper information and update the select bloc. Updating the bloc on each call to query would not be efficient. We could parse the query to check if some keywords are present like update and deduce the nature of the operation, but I am not sure that it would be reliable.

Do you have any solution or propositions about that in mind? What do you think?

synw commented 4 years ago

Thinking about it parsing the first word of the query to detect mutations (insert, update, delete) should be enough to inform the changefeed, at least for most common cases. The select bloc only needs to know that a mutation occurred in the table that it is watching to trigger a refresh and re-run the query.

We can try that to improve the behavior of query but there might be some edge cases from custom sql. If anyone wants to give it a shot prs are welcome

ederluca commented 4 years ago

Good afternoon

I agree if treating the words insert into, update, delete you will already have a satisfactory result I believe, because there are developers who like to put the full sql command I believe that adding this functionality for future versions would be a great gain.

synw commented 4 years ago

Ok so we agree on a plan. I'm a bit busy these days, if someone wants to try an implementation it would speed up the progress on this