Is it possible to listen to what has exactly changed in the DB? #1258
Replies: 6 comments 6 replies
-
You can use |
Beta Was this translation helpful? Give feedback.
-
This is also I question that I have. Do we get delete updates when using watch? |
Beta Was this translation helpful? Give feedback.
-
Awesome. Stupid question, how do you know something was removed from the
watch stream?
…On Sat, 12 Jun 2021 at 15:04, Simon Binder ***@***.***> wrote:
Do we get delete updates when using watch?
Yes, you should get them. Moor does not use update hooks because they
don't work on all tables, it has its own implementation.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1258 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACG2OVQTY5XIOEJ4CODYUZ3TSNEN7ANCNFSM46MJC5PQ>
.
|
Beta Was this translation helpful? Give feedback.
-
I absolutely understand that. But my issue is that I don't understand how I
differenciate between event's in the stream. All I get is a map with the
values from.the row, how do I know if this is a delete, update or insert?
…On Sat, 12 Jun 2021 at 15:34, Simon Binder ***@***.***> wrote:
Moor uses a fairly conservative algorithm for stream queries which mostly
involves saying "this stream reads from tables x, y and z, so it should
update when any of those tables is written to".
For instance, the DeleteStatement class in moor will inform the database
that there was a delete
<https://github.com/simolus3/moor/blob/ac30bb598946b0fbfb9e278e73cf9451c01e237c/moor/lib/src/runtime/query_builder/statements/delete.dart#L44-L45>
on table x, which will get propagated to the stream query. This may sound
inefficient, but it's good enough and more accurate implementations would
be pretty complicated (which also increases code size etc.). Moor is a bit
more sophisticated because we need to support views, foreign key
constraints with ON DELETE CASCADE and triggers which have an impact on
how stream queries are propagated.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1258 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACG2OVW3LED2MBL7YF2YIV3TSNH4JANCNFSM46MJC5PQ>
.
|
Beta Was this translation helpful? Give feedback.
-
I'm already doing something very similar but more rudimentary by just
keeping track of the hashCodes that were emited, so if the item was already
emited but the hash changed, then it's an update otherwise it's an insert.
The tricky part is with deletes, since I haven't find a way to know what
I'd had been removed.
…On Sun, 13 Jun 2021 at 22:47, Simon Binder ***@***.***> wrote:
Sorry, but I don't think we can reasonably provide this feature in moor.
Implementing it in Dart is impossible (think of triggers and other factors
that make it impossible for us to determine the right id in all scenarios),
and native update hooks are not available on all platforms.
You could run a regular query stream and then diff results to obtain
changes if that's what you need.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1258 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACG2OVTI43BXTDLHYWEHF6LTSUDNXANCNFSM46MJC5PQ>
.
|
Beta Was this translation helpful? Give feedback.
-
Thanks for all the awesome work you are doing.
On Sun, 13 Jun 2021 at 22:50, Razvan Cristian Lung ***@***.***>
wrote:
… I'm already doing something very similar but more rudimentary by just
keeping track of the hashCodes that were emited, so if the item was already
emited but the hash changed, then it's an update otherwise it's an insert.
The tricky part is with deletes, since I haven't find a way to know what
I'd had been removed.
On Sun, 13 Jun 2021 at 22:47, Simon Binder ***@***.***>
wrote:
> Sorry, but I don't think we can reasonably provide this feature in moor.
> Implementing it in Dart is impossible (think of triggers and other factors
> that make it impossible for us to determine the right id in all scenarios),
> and native update hooks are not available on all platforms.
>
> You could run a regular query stream and then diff results to obtain
> changes if that's what you need.
>
> —
> You are receiving this because you commented.
>
>
> Reply to this email directly, view it on GitHub
> <#1258 (reply in thread)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ACG2OVTI43BXTDLHYWEHF6LTSUDNXANCNFSM46MJC5PQ>
> .
>
|
Beta Was this translation helpful? Give feedback.
-
I was wondering if there's a way for an app to attach a listener to the DB and get events with information about what has changed?
This would include for instance, which table was updated, the kind of update (update, delete, insert) and what was changed.
Beta Was this translation helpful? Give feedback.
All reactions