Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/sqlite_async/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.14.1

- Fix update notifications sometimes firing before a write has completed.

## 0.14.0

- Support versions 3.x of the `sqlite3` package and 0.7.x of `sqlite3_web`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,24 @@ final class _LeasedContext extends UnscopedContext {
pool._returnIsolateWorker(worker);
}

Future<T> _runOnWorker<T>(FutureOr<T> Function(PoolConnection db) compute) {
return inner.unsafeAccess((connection) {
Future<T> _runOnWorker<T>(
FutureOr<T> Function(PoolConnection db) compute) async {
final (result, autocommit) = await inner.unsafeAccess((connection) async {
final ptr = connection.unsafePointer.address;
final checkInTransaction = verifyInTransaction;

return worker.run(_wrapDbClosure(ptr, checkInTransaction, compute));
final result =
await worker.run(_wrapDbClosure(ptr, checkInTransaction, compute));
return (result, connection.database.autocommit);
});

if (autocommit) {
if (inner case final ConnectionLease lease) {
await lease.notifyUpdates();
}
}

return result;
}

@override
Expand Down
4 changes: 2 additions & 2 deletions packages/sqlite_async/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: sqlite_async
description: High-performance asynchronous interface for SQLite on Dart and Flutter.
version: 0.14.0
version: 0.14.1
resolution: workspace
repository: https://github.com/powersync-ja/sqlite_async.dart
environment:
Expand All @@ -15,7 +15,7 @@ topics:
dependencies:
sqlite3: ^3.2.0
sqlite3_web: ^0.7.0
sqlite3_connection_pool: ^0.2.3
sqlite3_connection_pool: ^0.2.4
async: ^2.10.0
collection: ^1.17.0
meta: ^1.10.0
Expand Down
17 changes: 17 additions & 0 deletions packages/sqlite_async/test/native/watch_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,23 @@ void main() {
lastTime = r;
}
});

test('receives notifications before write lock returns', () async {
final db = await testUtils.setupDatabase(path: path);
await createTables(db);

final reads = StreamQueue(db.updates);
final first = reads.next;

db.writeLock((ctx) async {
await ctx.execute('INSERT INTO customer(name) VALUES (?)', ['test']);
// Because we're not in a transaction, this should emit an update. We
// shouldn't just collect updates at the end of writeLock to avoid
// long-running writers never emitting updates.
await first;
});
reads.cancel();
});
});
}

Expand Down
1 change: 1 addition & 0 deletions packages/sqlite_async/test/watch_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void main() {
db.updates.listen((_) => events++);
db.updates.listen((_) => events++);
await db.execute('INSERT INTO assets DEFAULT VALUES');
await pumpEventQueue();
expect(events, 2);
});

Expand Down