Skip to content

Commit 3a75258

Browse files
committed
Merge branch 'main' into feat/crud-transactions-warning
2 parents d267563 + 29d6faa commit 3a75258

File tree

4 files changed

+46
-39
lines changed

4 files changed

+46
-39
lines changed

demos/django-todolist/ios/Podfile.lock

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,28 @@ PODS:
33
- path_provider_foundation (0.0.1):
44
- Flutter
55
- FlutterMacOS
6-
- powersync-sqlite-core (0.1.6)
6+
- powersync-sqlite-core (0.2.1)
77
- powersync_flutter_libs (0.0.1):
88
- Flutter
9-
- powersync-sqlite-core (~> 0.1.6)
9+
- powersync-sqlite-core (~> 0.2.1)
1010
- shared_preferences_foundation (0.0.1):
1111
- Flutter
1212
- FlutterMacOS
13-
- "sqlite3 (3.46.0+1)":
14-
- "sqlite3/common (= 3.46.0+1)"
15-
- "sqlite3/common (3.46.0+1)"
16-
- "sqlite3/fts5 (3.46.0+1)":
13+
- "sqlite3 (3.46.1+1)":
14+
- "sqlite3/common (= 3.46.1+1)"
15+
- "sqlite3/common (3.46.1+1)"
16+
- "sqlite3/dbstatvtab (3.46.1+1)":
1717
- sqlite3/common
18-
- "sqlite3/perf-threadsafe (3.46.0+1)":
18+
- "sqlite3/fts5 (3.46.1+1)":
1919
- sqlite3/common
20-
- "sqlite3/rtree (3.46.0+1)":
20+
- "sqlite3/perf-threadsafe (3.46.1+1)":
21+
- sqlite3/common
22+
- "sqlite3/rtree (3.46.1+1)":
2123
- sqlite3/common
2224
- sqlite3_flutter_libs (0.0.1):
2325
- Flutter
24-
- sqlite3 (~> 3.46.0)
26+
- "sqlite3 (~> 3.46.0+1)"
27+
- sqlite3/dbstatvtab
2528
- sqlite3/fts5
2629
- sqlite3/perf-threadsafe
2730
- sqlite3/rtree
@@ -52,12 +55,12 @@ EXTERNAL SOURCES:
5255

5356
SPEC CHECKSUMS:
5457
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
55-
path_provider_foundation: 3784922295ac71e43754bd15e0653ccfd36a147c
56-
powersync-sqlite-core: 4c38c8f470f6dca61346789fd5436a6826d1e3dd
57-
powersync_flutter_libs: 5d6b132a398de442c0853a8b14bfbb62cd4ff5a1
58-
shared_preferences_foundation: b4c3b4cddf1c21f02770737f147a3f5da9d39695
59-
sqlite3: 292c3e1bfe89f64e51ea7fc7dab9182a017c8630
60-
sqlite3_flutter_libs: 0d611efdf6d1c9297d5ab03dab21b75aeebdae31
58+
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
59+
powersync-sqlite-core: 38ead13d8b21920cfbc79e9b3415b833574a506d
60+
powersync_flutter_libs: 9d26987384a376a18879b9d4fa71629407683163
61+
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
62+
sqlite3: 0bb0e6389d824e40296f531b858a2a0b71c0d2fb
63+
sqlite3_flutter_libs: c00457ebd31e59fa6bb830380ddba24d44fbcd3b
6164

6265
PODFILE CHECKSUM: f7b3cb7384a2d5da4b22b090e1f632de7f377987
6366

demos/django-todolist/lib/powersync.dart

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ class DjangoConnector extends PowerSyncBackendConnector {
3232
/// Get a token to authenticate against the PowerSync instance.
3333
@override
3434
Future<PowerSyncCredentials?> fetchCredentials() async {
35-
final prefs = await SharedPreferences.getInstance();
36-
final userId = prefs.getString('id');
35+
final userId = await getUserId();
3736
if (userId == null) {
3837
throw Exception('User does not have session');
3938
}
@@ -88,21 +87,23 @@ late final PowerSyncDatabase db;
8887
// Hacky flag to ensure the database is only initialized once, better to do this with listeners
8988
bool _dbInitialized = false;
9089

90+
/// id of the user currently logged in
91+
Future<String?> getUserId() async {
92+
final prefs = await SharedPreferences.getInstance();
93+
return prefs.getString('id');
94+
}
95+
9196
Future<bool> isLoggedIn() async {
92-
final prefs =
93-
await SharedPreferences.getInstance(); // Initialize SharedPreferences
94-
final userId = prefs.getString('id');
95-
if (userId != null) {
96-
return true;
97-
}
98-
return false;
97+
final userId = await getUserId();
98+
return userId != null;
9999
}
100100

101101
Future<String> getDatabasePath() async {
102102
final dir = await getApplicationSupportDirectory();
103103
return join(dir.path, 'powersync-demo.db');
104104
}
105105

106+
// opens the database and connects if logged in
106107
Future<void> openDatabase() async {
107108
// Open the local database
108109
if (!_dbInitialized) {
@@ -130,9 +131,3 @@ Future<void> openDatabase() async {
130131
Future<void> logout() async {
131132
await db.disconnectAndClear();
132133
}
133-
134-
/// id of the user currently logged in
135-
Future<String?> getUserId() async {
136-
final prefs = await SharedPreferences.getInstance();
137-
return prefs.getString('id');
138-
}

demos/supabase-todolist-optional-sync/lib/models/schema.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,15 @@ switchToSyncedSchema(PowerSyncDatabase db, String userId) async {
7979
await db.writeTransaction((tx) async {
8080
// Copy local-only data to the sync-enabled views.
8181
// This records each operation in the upload queue.
82+
// Overwrites the local-only owner_id value with the logged-in user's id.
8283
await tx.execute(
8384
'INSERT INTO $listsTable(id, name, created_at, owner_id) SELECT id, name, created_at, ? FROM inactive_local_$listsTable',
8485
[userId]);
8586

87+
// Overwrites the local-only created_by value with the logged-in user's id.
8688
await tx.execute(
87-
'INSERT INTO $todosTable SELECT * FROM inactive_local_$todosTable');
89+
'INSERT INTO $todosTable(id, list_id, created_at, completed_at, description, completed, created_by) SELECT id, list_id, created_at, completed_at, description, completed, ? FROM inactive_local_$todosTable',
90+
[userId]);
8891

8992
// Delete the local-only data.
9093
await tx.execute('DELETE FROM inactive_local_$todosTable');

packages/powersync/lib/src/open_factory/native/native_open_factory.dart

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ class PowerSyncOpenFactory extends AbstractPowerSyncOpenFactory {
1313
@Deprecated('Override PowerSyncOpenFactory instead.')
1414
final SqliteConnectionSetup? _sqliteSetup;
1515

16-
PowerSyncOpenFactory(
17-
{required super.path,
18-
super.sqliteOptions,
19-
@Deprecated('Override PowerSyncOpenFactory instead.')
20-
SqliteConnectionSetup? sqliteSetup})
21-
// ignore: deprecated_member_use_from_same_package
22-
: _sqliteSetup = sqliteSetup;
16+
PowerSyncOpenFactory({
17+
required super.path,
18+
super.sqliteOptions,
19+
@Deprecated('Override PowerSyncOpenFactory instead.')
20+
SqliteConnectionSetup? sqliteSetup,
21+
})
22+
// ignore: deprecated_member_use_from_same_package
23+
: _sqliteSetup = sqliteSetup;
2324

2425
@override
2526
void enableExtension() {
@@ -66,7 +67,12 @@ class PowerSyncOpenFactory extends AbstractPowerSyncOpenFactory {
6667
// ignore: deprecated_member_use_from_same_package
6768
_sqliteSetup?.setup();
6869

69-
enableExtension();
70+
try {
71+
enableExtension();
72+
} on PowersyncNotReadyException catch (e) {
73+
autoLogger.severe(e.message);
74+
rethrow;
75+
}
7076

7177
var db = super.open(options);
7278
db.execute('PRAGMA recursive_triggers = TRUE');

0 commit comments

Comments
 (0)