orbitinghail / sqlsync

SQLSync is a collaborative offline-first wrapper around SQLite. It is designed to synchronize web application state between users, devices, and the edge.
https://sqlsync.dev
Apache License 2.0
2.19k stars 28 forks source link

Server-initiated mutations #42

Closed carlsverre closed 6 months ago

carlsverre commented 6 months ago

Plan

Expose a new APIs on the CoordinatorDocument type called mutate_direct which takes a callback of the form (tx: &mut Transaction) -> Result<()>. Internally it grabs a txn from sqlite, runs the cb, runs storage.commit and then returns. If the cb fails, the txn will be rolled back (and possibly storage reverted).

Note: this api is specifically designed to discourage long-lived txns as SQLSync is single threaded and thus while this txn runs no other mutations can execute.

Discussed in https://github.com/orbitinghail/sqlsync/discussions/41

Originally posted by **matthewgapp** January 4, 2024 I have an instance of the coordinator running on our server and I am using the pluggable reducer I wrote (https://github.com/orbitinghail/sqlsync/pull/40). But it's not quite enough, because I need to incorporate server-initiated mutations that are then synced to all clients. Is there an existing API I can use? Perhaps the `write_lsn` method?