fix: Close generated sync sessions and expose the shared demo (#135)
This commit is contained in:
parent
4789f650be
commit
0f4b8116f4
1 changed files with 266 additions and 35 deletions
|
|
@ -9,23 +9,25 @@ them converge.
|
|||
|
||||
If you are here to learn the package, read **`lib/src/offline_replica.dart`**
|
||||
first — it is the entire integration in ~60 lines, deliberately free of demo and
|
||||
UI code. Every replica follows the same four steps:
|
||||
UI code. Every replica follows the same three steps:
|
||||
|
||||
1. **Open a local database.** `client.createSession(path)` opens a Serverpod
|
||||
client database (a local SQLite file) and runs the client migrations.
|
||||
2. **Wrap it for CRDT sync.** `OfflineSyncDatabaseSession.wraps(raw, syncTables: …,
|
||||
persistentUserId: …)`, then `offlineSyncSession.db.initialize()` to establish this
|
||||
device's CRDT node so it can take part in sync.
|
||||
3. **Read and write generated models** against that session, e.g.
|
||||
1. **Open a sync session.** The generated
|
||||
`client.createSyncSession(path, isDebugMode: kDebugMode, persistentUserId: …)`
|
||||
opens the local SQLite database, runs client migrations, wraps the generated
|
||||
sync tables, and initializes CRDT tracking.
|
||||
2. **Read and write generated models** against that session, e.g.
|
||||
`Person.db.insertRow(session, person)` or `session.db.find<Person>()`. (The
|
||||
demo also routes these through a generic `TableOps` registry so its
|
||||
metadata-driven UI can touch any table without a per-type switch — that part
|
||||
is demo-only; the `seed*` methods in `lib/src/demo_controller.dart` show the
|
||||
plain form.)
|
||||
4. **Synchronize through a Serverpod client.**
|
||||
3. **Synchronize through a Serverpod client.**
|
||||
`client.offlineSync.syncOnce(session, onMergeSuccess: …)` for a one-shot push/pull,
|
||||
or `client.offlineSync.syncContinuously(session, …)` to stream until cancelled.
|
||||
|
||||
When disposing a replica, cancel its sync subscription and call `session.close()`
|
||||
to release the local database connection.
|
||||
|
||||
Connectivity is just *which client you sync through*: the demo swaps
|
||||
`Client.httpClientOverride` between a real transport and a failing one to
|
||||
simulate going offline — the local database is untouched either way.
|
||||
|
|
|
|||
Loading…
Reference in a new issue