Skip to content

Commit 9ad96f4

Browse files
committed
Updated readme. Tried making the schema documentation clearer by changing the local and online prefixes.
1 parent 4c24182 commit 9ad96f4

File tree

10 files changed

+33
-32
lines changed

10 files changed

+33
-32
lines changed

demos/local-only-todolist/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# PowerSync + Supabase Flutter Local Only to Online Mode Demo: Todo List App
1+
# PowerSync + Supabase Flutter Local-Only to Online Mode Demo: Todo List App
22

3-
This demo app is an extension of the Flutter Todo List App that demonstrates how to use the PowerSync SDK for Flutter in an local only way. It allows the user to use the app offline without having to sign in. After signing in data that was kept locally is synced up. For a step-by-step guide, see [here](https://docs.powersync.com/integration-guides/supabase).
3+
This demo app is an extension of the Supabase Todo List App that demonstrates how to use the PowerSync SDK for Flutter in a local-only way without sync capabilities. It allows the user to use the app offline without having to sign in. After signing in data that was kept locally is synced up. For a step-by-step guide, see [here](https://docs.powersync.com/integration-guides/supabase).
44

55
# Running the app with local-only
66

@@ -49,7 +49,7 @@ Insert the credentials of your new Supabase and PowerSync projects into `lib/app
4949

5050
# Explanation
5151

52-
The demo implements local-only and synced modes by using two sets of schema definitions, which can be viewed [here](./lib/models/schema.dart). The app initially starts in local only mode with the offline schema. When the user signs in, the database schema is updated to the online schema, and the data is migrated to enable synchronization.
52+
The demo implements local-only and synced modes by using two sets of schema definitions, which can be viewed [here](./lib/models/schema.dart). The app initially starts in local-only mode with the offline schema. When the user signs in, the database schema is updated to the online schema, and the data is migrated to enable synchronization.
5353

5454
After 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.dart). Note that any other local storage solution would work as long as it's not using the PowerSync database (chicken and egg problem).
5555

demos/local-only-todolist/android/app/src/main/AndroidManifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="co.powersync.demotodolist">
33
<application
4-
android:label="PowerSync Supabase Local Only Demo"
4+
android:label="PowerSync Supabase Local-Only Demo"
55
android:name="${applicationName}"
66
android:icon="@mipmap/ic_launcher">
77
<activity

demos/local-only-todolist/ios/Runner/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<key>CFBundleDevelopmentRegion</key>
88
<string>$(DEVELOPMENT_LANGUAGE)</string>
99
<key>CFBundleDisplayName</key>
10-
<string>Powersync Flutter Local Only Demo</string>
10+
<string>Powersync Flutter Local-Only Demo</string>
1111
<key>CFBundleExecutable</key>
1212
<string>$(EXECUTABLE_NAME)</string>
1313
<key>CFBundleIdentifier</key>

demos/local-only-todolist/lib/main.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class MyApp extends StatelessWidget {
5858
@override
5959
Widget build(BuildContext context) {
6060
return MaterialApp(
61-
title: 'PowerSync Flutter Local Only Demo',
61+
title: 'PowerSync Flutter Local-Only Demo',
6262
theme: ThemeData(
6363
primarySwatch: Colors.blue,
6464
),

demos/local-only-todolist/lib/models/schema.dart

+21-20
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
11
import 'package:powersync/powersync.dart';
22
import 'package:powersync_flutter_local_only_demo/models/sync_mode.dart';
33

4-
/// This schema design supports an online/local-only workflow by managing data
4+
/// This schema design supports a local-only to online workflow by managing data
55
/// across two versions of each table: one for local/offline use and one for
66
/// online/synced use. This approach simplifies the handling of data in different
77
/// connectivity states.
88
///
9-
/// For local only, the views become:
10-
/// online_todos
9+
/// For local-only, the views become:
10+
/// inactive_synced_todos
1111
/// todos
12-
/// online_lists
12+
/// inactive_synced_lists
1313
/// lists
1414
///
1515
/// - 'todos' and 'lists' refer to the local-only data.
16-
/// - 'online_todos' and 'online_lists' refer to the data that will be synced
17-
/// once online, making it clear that these are not currently synchronized.
16+
/// - 'inactive_synced_todos' and 'inactive_synced_lists' refer to the data that will be synced
17+
/// once online.
1818
///
1919
/// For online, we have these views:
2020
/// todos
21-
/// local_todos
21+
/// inactive_local_todos
2222
/// lists
23-
/// local_lists
23+
/// inactive_local_lists
2424
///
2525
/// - 'todos' and 'lists' refer to the synced/online data.
26-
/// - local_todos' and 'local_lists' refer to the local-only data, allowing
26+
/// - `inactive_local_todos' and 'inactive_local_lists' refer to the local-only data, allowing
2727
/// for temporary storage or operations before syncing.
2828
///
2929
/// For an offline-to-online transition [switchToOnlineSchema] copies data so that it ends up in the upload queue.
3030
3131
const todosTable = 'todos';
3232
const listsTable = 'lists';
3333

34-
Schema makeSchema({online = bool}) {
34+
Schema makeSchema({synced = bool}) {
3535
String onlineName(String table) {
36-
if (online) {
36+
if (synced) {
3737
return table;
3838
} else {
39-
return "online_$table";
39+
return "inactive_synced_$table";
4040
}
4141
}
4242

4343
String localName(String table) {
44-
if (online) {
45-
return "local_$table";
44+
if (synced) {
45+
return "inactive_local_$table";
4646
} else {
4747
return table;
4848
}
@@ -79,20 +79,21 @@ Schema makeSchema({online = bool}) {
7979
}
8080

8181
switchToOnlineSchema(PowerSyncDatabase db, String userId) async {
82-
await db.updateSchema(makeSchema(online: true));
82+
await db.updateSchema(makeSchema(synced: true));
8383
await setSyncEnabled(true);
8484

8585
await db.writeTransaction((tx) async {
86-
// Copy local data to the "online" views.
86+
// Copy local-only data to the "online" views.
8787
// This records each operation to the crud queue.
8888
await tx.execute(
89-
'INSERT INTO lists(id, name, created_at, owner_id) SELECT id, name, created_at, ? FROM local_lists',
89+
'INSERT INTO lists(id, name, created_at, owner_id) SELECT id, name, created_at, ? FROM inactive_local_lists',
9090
[userId]);
9191

92-
await tx.execute('INSERT INTO $todosTable SELECT * FROM local_$todosTable');
92+
await tx.execute(
93+
'INSERT INTO $todosTable SELECT * FROM inactive_local_$todosTable');
9394

9495
// Delete the "local-only" data.
95-
await tx.execute('DELETE FROM local_$todosTable');
96-
await tx.execute('DELETE FROM local_$listsTable');
96+
await tx.execute('DELETE FROM inactive_local_$todosTable');
97+
await tx.execute('DELETE FROM inactive_local_$listsTable');
9798
});
9899
}

demos/local-only-todolist/lib/powersync.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ bool isLoggedIn() {
143143
/// id of the user currently logged in
144144
String getUserId() {
145145
return Supabase.instance.client.auth.currentSession?.user.id ??
146-
'00000000-0000-0000-0000-000000000000'; // default ID supplied for local only mode
146+
'00000000-0000-0000-0000-000000000000'; // default ID supplied for local-only mode
147147
}
148148

149149
Future<String> getDatabasePath() async {
@@ -159,7 +159,7 @@ Future<String> getDatabasePath() async {
159159
Future<void> openDatabase() async {
160160
var isSyncMode = await getSyncEnabled();
161161
db = PowerSyncDatabase(
162-
schema: makeSchema(online: isSyncMode),
162+
schema: makeSchema(synced: isSyncMode),
163163
path: await getDatabasePath(),
164164
logger: attachedLogger);
165165
await db.initialize();

demos/local-only-todolist/lib/widgets/login_page.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class _LoginPageState extends State<LoginPage> {
6363
Widget build(BuildContext context) {
6464
return Scaffold(
6565
appBar: AppBar(
66-
title: const Text("PowerSync Flutter Local Only Demo"),
66+
title: const Text("PowerSync Flutter Local-Only Demo"),
6767
),
6868
body: Center(
6969
child: SingleChildScrollView(

demos/local-only-todolist/lib/widgets/signup_page.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class _SignupPageState extends State<SignupPage> {
6767
Widget build(BuildContext context) {
6868
return Scaffold(
6969
appBar: AppBar(
70-
title: const Text("PowerSync Flutter Local Only Demo"),
70+
title: const Text("PowerSync Flutter Local-Only Demo"),
7171
),
7272
body: Center(
7373
child: SingleChildScrollView(

demos/local-only-todolist/macos/Runner/Configs/AppInfo.xcconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// 'flutter create' template.
66

77
// The application's name. By default this is also the title of the Flutter window.
8-
PRODUCT_NAME = PowerSync Supabase Local Only Demo
8+
PRODUCT_NAME = PowerSync Supabase Local-Only Demo
99

1010
// The application's bundle identifier
1111
PRODUCT_BUNDLE_IDENTIFIER = co.powersync.demotodolist

demos/local-only-todolist/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: powersync_flutter_local_only_demo
2-
description: PowerSync Flutter Local Only Demo
2+
description: PowerSync Flutter Local-Only Demo
33
publish_to: "none"
44

55
version: 1.0.1

0 commit comments

Comments
 (0)