You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: demos/local-only-todolist/README.md
+5-7
Original file line number
Diff line number
Diff line change
@@ -40,7 +40,7 @@ It does the following:
40
40
41
41
## Configure your PowerSync Instance
42
42
43
-
Create a new PowerSync instance, connecting to the database of the Supabase project.
43
+
Create a new PowerSync instance, connecting to the database of the Supabase project. See instructions [here](https://docs.powersync.com/integration-guides/supabase-+-powersync#connect-powersync-to-your-supabase).
44
44
45
45
Then deploy the following sync rules:
46
46
@@ -60,7 +60,7 @@ Insert the credentials of your Supabase and PowerSync projects into `lib/app_con
60
60
61
61
## Sign in to the app
62
62
63
-
Reload the app and sign up or sign in. Once successfully signed in, existing and new data should seamlessly sync with Supabase.
63
+
Restart the app and sign up or sign in. Once successfully signed in, existing and new data should seamlessly sync with Supabase.
64
64
65
65
66
66
# How this works
@@ -79,26 +79,24 @@ The downside to this approach is that app queries would need to continuously dif
79
79
80
80
## Recommended implementation
81
81
82
-
To keep app queries consistent between the two states, we utilize the [viewName](https://pub.dev/documentation/powersync/latest/powersync/Table/viewName.html) property, which allows overriding the default name of the view that is used in queries.
82
+
To keep app queries consistent between the two states, we utilize the [viewName](https://pub.dev/documentation/powersync/latest/powersync/Table/viewName.html) property, which allows overriding the default name of schema views (each table automatically has a corresponding view, defaulting to the table name, which is used in queries).
83
83
84
84
This looks as follows in the local-only state:
85
85
86
86

87
87
88
-
The local-only tables (`local_lists` and `local_todos`) have their view names overriden to `listsAlias` and `todosAlias`, and these names are used in queries (e.g. `PowerSync.getAll("SELECT * FROM listsAlias");`). The `lists` and `todos` tablesare not used in this state, but will become relevant in the next step.
88
+
The local-only tables (`local_lists` and `local_todos`) have their view names overriden to `lists` and `todos`, and these names are used in queries (e.g. `PowerSync.getAll("SELECT * FROM lists");`). The `lists` and `todos` tables, which are the sync-enabled tables without the `localOnly` flag, are not used at this stage, as indicated by their `inactive_synced_` view names.
89
89
90
90
When the user registers / signs in:
91
91
92
92

93
93
94
-
The _synced_ tables (`lists` and `todos`) now have their view names overriden to `listsAlias` and `todosAlias`. Note that `updateSchema` must be run to update the view name. See the [schema](./lib/models/schema.dart) for details about this. The app query `PowerSync.getAll("SELECT * FROM listsAlias")` now reads data from the `lists` table.
94
+
The _synced_ tables (`lists` and `todos`) now have their view names set to `lists` and `todos`. Note that `updateSchema` must be run to update the view name. See the [schema](./lib/models/schema.dart) for details about this. The app query `PowerSync.getAll("SELECT * FROM lists")` now reads data from the `lists` table.
95
95
96
96
Finally, copy data from the local-only tables to the synced tables, and delete data from the local-only tables to reduce database size:
97
97
98
98

99
99
100
-
101
-
102
100
At this point, being signed in no longer determines which schema should be used, as the user's session expiring and explicitly signing out trigger different behaviors. If the session expires, the user can continue interacting with their data. However, if the user explicitly logs out, all data is cleared, effectively resetting the app. To manage this, an additional local storage mechanism is used to track which schema is currently in use, as seen [here](./lib/models/sync_mode.dart). Note that any other local storage solution would work as long as it's not using the PowerSync database (chicken and egg problem).
0 commit comments