Skip to content
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

Any plans to implement sqlite3_update_hook? #61

Closed
reinhardbluelab opened this issue Nov 27, 2021 · 3 comments
Closed

Any plans to implement sqlite3_update_hook? #61

reinhardbluelab opened this issue Nov 27, 2021 · 3 comments

Comments

@reinhardbluelab
Copy link

We have a trigger (before insert) that inserts into another table. Using the watch() function in Drift does not seem to fire the callback for the update of the other table; it does fire the update for the original (i.e. Drift initiated) table though.

https://www.sqlite.org/c3ref/update_hook.html

Any thoughts on implementing this so that a Dart callback could be called for all (and not only Drift insertion) table updates?

Keep up the great work!

@simolus3
Copy link
Owner

Using the watch() function in Drift does not seem to fire the callback for the update of the other table

It definitely should though! Are you defining the trigger in a .drift file or are you creating it manually? For triggers that Drift knows about, stream updates should work.

I think update hooks could be a useful addition to this package regardless of Drift though.

@reinhardbluelab
Copy link
Author

At the moment we're creating these triggers manually since they rely on a complex view that doesn't work in a .drift file. We're just running these in a customStatement.

@simolus3
Copy link
Owner

I have implemented update hooks in 8d308c1.

At the moment we're creating these triggers manually since they rely on a complex view that doesn't work in a .drift file

If drift crashes or provides invalid analysis for a valid sqlite3 view, I'd love to take a look at that. If you're using customStatements to create triggers, you need to tell drift how these affect stream updates manually (the generator should otherwise be able to figure it out).

  @override
  StreamQueryUpdateRules get streamUpdateRules {
    return StreamQueryUpdateRules(
      [
        ...super.streamUpdateRules.rules,
        WritePropagation(
          on: TableUpdateQuery.onTable(tableThatTheTriggerIsListeningOn),
          result: [
            TableUpdate.onTable(tableThatMightBeWrittenInto),
          ],
        )
      ],
    );
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants