diff --git a/CHANGELOG.md b/CHANGELOG.md index d9cda07..cafde71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,30 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## 2025-07-29 + +--- + +Packages with breaking changes: + + - There are no breaking changes in this release. + +Packages with other changes: + + - [`sqlite_async` - `v0.11.8`](#sqlite_async---v0118) + - [`drift_sqlite_async` - `v0.2.3`](#drift_sqlite_async---v023) + +--- + +#### `sqlite_async` - `v0.11.8` + +- Support nested transactions (emulated with `SAVEPOINT` statements). +- Fix web compilation issues with version `2.8.0` of `package:sqlite3`. + +#### `drift_sqlite_async` - `v0.2.3` + +- Support nested transactions. + ## 2025-06-03 --- diff --git a/packages/drift_sqlite_async/CHANGELOG.md b/packages/drift_sqlite_async/CHANGELOG.md index b101ac4..e70cd40 100644 --- a/packages/drift_sqlite_async/CHANGELOG.md +++ b/packages/drift_sqlite_async/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.3 + +- Support nested transactions. + ## 0.2.2 - Fix write detection when using UPDATE/INSERT/DELETE with RETURNING in raw queries. diff --git a/packages/drift_sqlite_async/lib/src/executor.dart b/packages/drift_sqlite_async/lib/src/executor.dart index 41886f3..127462e 100644 --- a/packages/drift_sqlite_async/lib/src/executor.dart +++ b/packages/drift_sqlite_async/lib/src/executor.dart @@ -129,13 +129,28 @@ class _SqliteAsyncTransactionDelegate extends SupportedTransactionDelegate { _SqliteAsyncTransactionDelegate(this._db); + @override + FutureOr Function(QueryDelegate, Future Function(QueryDelegate))? + get startNested => _startNested; + @override Future startTransaction(Future Function(QueryDelegate p1) run) async { - await _db.writeTransaction((context) async { + await _startTransaction(_db, run); + } + + Future _startTransaction( + SqliteWriteContext context, Future Function(QueryDelegate p1) run) async { + await context.writeTransaction((context) async { final delegate = _SqliteAsyncQueryDelegate(context, null); return run(delegate); }); } + + Future _startNested( + QueryDelegate outer, Future Function(QueryDelegate) block) async { + await _startTransaction( + (outer as _SqliteAsyncQueryDelegate)._context, block); + } } class _SqliteAsyncVersionDelegate extends DynamicVersionDelegate { diff --git a/packages/drift_sqlite_async/pubspec.yaml b/packages/drift_sqlite_async/pubspec.yaml index 62a64da..77f250d 100644 --- a/packages/drift_sqlite_async/pubspec.yaml +++ b/packages/drift_sqlite_async/pubspec.yaml @@ -1,5 +1,5 @@ name: drift_sqlite_async -version: 0.2.2 +version: 0.2.3 homepage: https://github.com/powersync-ja/sqlite_async.dart repository: https://github.com/powersync-ja/sqlite_async.dart description: Use Drift with a sqlite_async database, allowing both to be used in the same application. @@ -14,12 +14,12 @@ topics: environment: sdk: ">=3.0.0 <4.0.0" dependencies: - drift: ">=2.19.0 <3.0.0" - sqlite_async: ^0.11.0 + drift: ">=2.28.0 <3.0.0" + sqlite_async: ^0.11.8 dev_dependencies: build_runner: ^2.4.8 - drift_dev: ">=2.19.0 <3.0.0" + drift_dev: ">=2.28.0 <3.0.0" glob: ^2.1.2 lints: ^5.0.0 sqlite3: ^2.4.0 diff --git a/packages/drift_sqlite_async/test/db_test.dart b/packages/drift_sqlite_async/test/db_test.dart index bda09df..f5b269a 100644 --- a/packages/drift_sqlite_async/test/db_test.dart +++ b/packages/drift_sqlite_async/test/db_test.dart @@ -117,5 +117,35 @@ void main() { final deleted = await dbu.delete(dbu.todoItems).go(); expect(deleted, 10); }); + + test('nested transactions', () async { + await dbu + .into(dbu.todoItems) + .insert(TodoItemsCompanion.insert(description: 'root')); + + await dbu.transaction(() async { + await dbu + .into(dbu.todoItems) + .insert(TodoItemsCompanion.insert(description: 'tx0')); + + await dbu.transaction(() async { + await dbu + .into(dbu.todoItems) + .insert(TodoItemsCompanion.insert(description: 'tx1')); + + await expectLater(() { + return dbu.transaction(() async { + await dbu + .into(dbu.todoItems) + .insert(TodoItemsCompanion.insert(description: 'tx2')); + throw 'rollback'; + }); + }, throwsA(anything)); + }); + }); + + final items = await dbu.todoItems.all().get(); + expect(items.map((e) => e.description).toSet(), {'root', 'tx0', 'tx1'}); + }); }); } diff --git a/packages/sqlite_async/CHANGELOG.md b/packages/sqlite_async/CHANGELOG.md index 97dbf50..387c944 100644 --- a/packages/sqlite_async/CHANGELOG.md +++ b/packages/sqlite_async/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.11.8 + +- Support nested transactions (emulated with `SAVEPOINT` statements). +- Fix web compilation issues with version `2.8.0` of `package:sqlite3`. + ## 0.11.7 - Shared worker: Release locks owned by connected client tab when it closes. diff --git a/packages/sqlite_async/pubspec.yaml b/packages/sqlite_async/pubspec.yaml index e610d7f..a155f2b 100644 --- a/packages/sqlite_async/pubspec.yaml +++ b/packages/sqlite_async/pubspec.yaml @@ -1,6 +1,6 @@ name: sqlite_async description: High-performance asynchronous interface for SQLite on Dart and Flutter. -version: 0.11.7 +version: 0.11.8 repository: https://github.com/powersync-ja/sqlite_async.dart environment: sdk: ">=3.5.0 <4.0.0"