Skip to content

Commit d475986

Browse files
committed
Merge remote-tracking branch 'origin/fix-update-ids'
2 parents d5daf8c + 09157e6 commit d475986

File tree

6 files changed

+50
-12
lines changed

6 files changed

+50
-12
lines changed

Diff for: sqlite3_web/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.3.1
2+
3+
- Fix hooks not being delivered to all databases.
4+
15
## 0.3.0
26

37
- Allow passing data to worker when opening databases.

Diff for: sqlite3_web/lib/src/worker.dart

+4-6
Original file line numberDiff line numberDiff line change
@@ -249,26 +249,24 @@ final class _ClientConnection extends ProtocolChannel
249249
return await subscribe(database!.updates, () async {
250250
final rawDatabase = await database.database.opened;
251251
return rawDatabase.database.updates.listen((event) {
252-
sendNotification(UpdateNotification(
253-
update: event, databaseId: database.database.id));
252+
sendNotification(
253+
UpdateNotification(update: event, databaseId: database.id));
254254
});
255255
}, request);
256256
case StreamRequest(action: true, type: MessageType.commitRequest):
257257
return await subscribe(database!.commits, () async {
258258
final rawDatabase = await database.database.opened;
259259
return rawDatabase.database.commits.listen((event) {
260260
sendNotification(EmptyNotification(
261-
type: MessageType.notifyCommit,
262-
databaseId: database.database.id));
261+
type: MessageType.notifyCommit, databaseId: database.id));
263262
});
264263
}, request);
265264
case StreamRequest(action: true, type: MessageType.rollbackRequest):
266265
return await subscribe(database!.rollbacks, () async {
267266
final rawDatabase = await database.database.opened;
268267
return rawDatabase.database.rollbacks.listen((event) {
269268
sendNotification(EmptyNotification(
270-
type: MessageType.notifyRollback,
271-
databaseId: database.database.id));
269+
type: MessageType.notifyRollback, databaseId: database.id));
272270
});
273271
}, request);
274272
case StreamRequest(action: false):

Diff for: sqlite3_web/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: sqlite3_web
22
description: Utilities to simplify accessing sqlite3 on the web, with automated feature detection.
3-
version: 0.3.0
3+
version: 0.3.1
44
homepage: https://github.com/simolus3/sqlite3.dart/tree/main/sqlite3_web
55
repository: https://github.com/simolus3/sqlite3.dart
66

Diff for: sqlite3_web/test/integration_test.dart

+4
Original file line numberDiff line numberDiff line change
@@ -258,5 +258,9 @@ final class _TestConfiguration {
258258
await driver.checkReadWrite();
259259
});
260260
}
261+
262+
test('can share databases', () async {
263+
await driver.testSecond();
264+
});
261265
}
262266
}

Diff for: sqlite3_web/tool/server.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class TestWebDriver {
187187
await driver.executeAsync('exec(arguments[0], arguments[1])', [sql]);
188188
}
189189

190-
Future<void> testSecond(String sql) async {
190+
Future<void> testSecond() async {
191191
final res = await driver.executeAsync('test_second("", arguments[0])', []);
192192
if (res != true) {
193193
throw 'test_second failed! More information may be available in the console.';

Diff for: sqlite3_web/web/main.dart

+36-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'dart:js_interop_unsafe';
44
import 'dart:typed_data';
55

66
import 'package:sqlite3_web/sqlite3_web.dart';
7+
import 'package:sqlite3_web/src/client.dart';
78
import 'package:web/web.dart';
89

910
import 'controller.dart';
@@ -43,12 +44,43 @@ void main() {
4344
_addCallbackForWebDriver('open_only_vfs', (arg) => _open(arg, true));
4445
_addCallbackForWebDriver('exec', _exec);
4546
_addCallbackForWebDriver('test_second', (arg) async {
46-
final endpoint = await database!.additionalConnection();
47-
final second = await WebSqlite.connectToPort(endpoint);
47+
final sqlite = initializeSqlite();
48+
// Open one database to occupy the database id of zero in the worker
49+
final unused = await sqlite.connect(
50+
'a', StorageMode.inMemory, AccessMode.throughSharedWorker);
51+
await unused.execute('CREATE TABLE unused (bar TEXT);');
52+
53+
// Then open another one
54+
final first = await sqlite.connect(
55+
'b', StorageMode.inMemory, AccessMode.throughSharedWorker)
56+
as RemoteDatabase;
57+
await first.execute('CREATE TABLE foo (bar TEXT);');
58+
59+
final endpoint = await first.additionalConnection();
60+
final second = await WebSqlite.connectToPort(endpoint) as RemoteDatabase;
61+
62+
// First and second should have different internal ids (that's what the
63+
// setup with the unused database was trying to accomplish).
64+
if (first.databaseId == second.databaseId) {
65+
return 'Unexpected same id'.toJS;
66+
}
67+
68+
await second.execute('SELECT * FROM foo;');
69+
70+
var receivedUpdates = 0;
71+
second.updates.listen((_) => receivedUpdates++);
4872

49-
await second.execute('SELECT 1');
73+
await first.execute('INSERT INTO foo VALUES (?)', ['a']);
74+
await unused.execute('INSERT INTO unused VALUES (?)', ['a']);
75+
76+
await Future.delayed(const Duration(milliseconds: 200));
77+
78+
await unused.dispose();
79+
await first.dispose();
5080
await second.dispose();
51-
return true.toJS;
81+
// This should have received the update from the first database without
82+
// receiving the one from the unrelated database.
83+
return (receivedUpdates == 1).toJS;
5284
});
5385
_addCallbackForWebDriver('assert_file', (arg) async {
5486
final vfs = database!.fileSystem;

0 commit comments

Comments
 (0)