powersync-ja / react-native-quick-sqlite

Embedded SQLite with JSI bindings
MIT License
5 stars 2 forks source link

[Fix] Table change updates in write transactions #13

Closed stevensJourney closed 7 months ago

stevensJourney commented 8 months ago

This PR fixes an issue where table change updates registered via registerUpdateHook would trigger from writeTransactions before the changes have been committed or rolled back.

If a client used the update hook to trigger a read from a read connection the updated data would not yet be visible. This causes inconsistent results when implementing watched queries.

This PR monitors the state of write transactions in order to emit update events only once the changes have been committed. This work is looseley based of the implementation here https://github.com/powersync-ja/sqlite_async.dart/blob/f994e165d5410c9ccca9a187de9c51fcedfd1182/lib/src/sqlite_connection_impl.dart#L310.

This PR also adds extra listeners which emit events for all table changes and write transaction events. This gives users access to table changes during transactions and allows for custom logic for deferring table change events during transactions.

stevensJourney commented 7 months ago

Automated tests are currently a bit broken. The Android emulator seems to be freezing at random intervals. Sometimes before tests begin and sometimes during tests. Tests have been verified locally on Android and iOS image image Watched queries have also been verified in here https://github.com/powersync-ja/powersync-react-native-sdk/pull/43