Skip to content

Commit 76e3a20

Browse files
authored
Merge pull request #103 from powersync-ja/drift-nested-transactions
Drift: Support nested transactions
2 parents 6d8500f + 17012ed commit 76e3a20

File tree

7 files changed

+84
-6
lines changed

7 files changed

+84
-6
lines changed

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,30 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
## 2025-07-29
7+
8+
---
9+
10+
Packages with breaking changes:
11+
12+
- There are no breaking changes in this release.
13+
14+
Packages with other changes:
15+
16+
- [`sqlite_async` - `v0.11.8`](#sqlite_async---v0118)
17+
- [`drift_sqlite_async` - `v0.2.3`](#drift_sqlite_async---v023)
18+
19+
---
20+
21+
#### `sqlite_async` - `v0.11.8`
22+
23+
- Support nested transactions (emulated with `SAVEPOINT` statements).
24+
- Fix web compilation issues with version `2.8.0` of `package:sqlite3`.
25+
26+
#### `drift_sqlite_async` - `v0.2.3`
27+
28+
- Support nested transactions.
29+
630
## 2025-06-03
731

832
---

packages/drift_sqlite_async/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.2.3
2+
3+
- Support nested transactions.
4+
15
## 0.2.2
26

37
- Fix write detection when using UPDATE/INSERT/DELETE with RETURNING in raw queries.

packages/drift_sqlite_async/lib/src/executor.dart

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,28 @@ class _SqliteAsyncTransactionDelegate extends SupportedTransactionDelegate {
129129

130130
_SqliteAsyncTransactionDelegate(this._db);
131131

132+
@override
133+
FutureOr<void> Function(QueryDelegate, Future<void> Function(QueryDelegate))?
134+
get startNested => _startNested;
135+
132136
@override
133137
Future<void> startTransaction(Future Function(QueryDelegate p1) run) async {
134-
await _db.writeTransaction((context) async {
138+
await _startTransaction(_db, run);
139+
}
140+
141+
Future<void> _startTransaction(
142+
SqliteWriteContext context, Future Function(QueryDelegate p1) run) async {
143+
await context.writeTransaction((context) async {
135144
final delegate = _SqliteAsyncQueryDelegate(context, null);
136145
return run(delegate);
137146
});
138147
}
148+
149+
Future<void> _startNested(
150+
QueryDelegate outer, Future<void> Function(QueryDelegate) block) async {
151+
await _startTransaction(
152+
(outer as _SqliteAsyncQueryDelegate)._context, block);
153+
}
139154
}
140155

141156
class _SqliteAsyncVersionDelegate extends DynamicVersionDelegate {

packages/drift_sqlite_async/pubspec.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: drift_sqlite_async
2-
version: 0.2.2
2+
version: 0.2.3
33
homepage: https://github.com/powersync-ja/sqlite_async.dart
44
repository: https://github.com/powersync-ja/sqlite_async.dart
55
description: Use Drift with a sqlite_async database, allowing both to be used in the same application.
@@ -14,12 +14,12 @@ topics:
1414
environment:
1515
sdk: ">=3.0.0 <4.0.0"
1616
dependencies:
17-
drift: ">=2.19.0 <3.0.0"
18-
sqlite_async: ^0.11.0
17+
drift: ">=2.28.0 <3.0.0"
18+
sqlite_async: ^0.11.8
1919

2020
dev_dependencies:
2121
build_runner: ^2.4.8
22-
drift_dev: ">=2.19.0 <3.0.0"
22+
drift_dev: ">=2.28.0 <3.0.0"
2323
glob: ^2.1.2
2424
lints: ^5.0.0
2525
sqlite3: ^2.4.0

packages/drift_sqlite_async/test/db_test.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,35 @@ void main() {
117117
final deleted = await dbu.delete(dbu.todoItems).go();
118118
expect(deleted, 10);
119119
});
120+
121+
test('nested transactions', () async {
122+
await dbu
123+
.into(dbu.todoItems)
124+
.insert(TodoItemsCompanion.insert(description: 'root'));
125+
126+
await dbu.transaction(() async {
127+
await dbu
128+
.into(dbu.todoItems)
129+
.insert(TodoItemsCompanion.insert(description: 'tx0'));
130+
131+
await dbu.transaction(() async {
132+
await dbu
133+
.into(dbu.todoItems)
134+
.insert(TodoItemsCompanion.insert(description: 'tx1'));
135+
136+
await expectLater(() {
137+
return dbu.transaction(() async {
138+
await dbu
139+
.into(dbu.todoItems)
140+
.insert(TodoItemsCompanion.insert(description: 'tx2'));
141+
throw 'rollback';
142+
});
143+
}, throwsA(anything));
144+
});
145+
});
146+
147+
final items = await dbu.todoItems.all().get();
148+
expect(items.map((e) => e.description).toSet(), {'root', 'tx0', 'tx1'});
149+
});
120150
});
121151
}

packages/sqlite_async/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.11.8
2+
3+
- Support nested transactions (emulated with `SAVEPOINT` statements).
4+
- Fix web compilation issues with version `2.8.0` of `package:sqlite3`.
5+
16
## 0.11.7
27

38
- Shared worker: Release locks owned by connected client tab when it closes.

packages/sqlite_async/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: sqlite_async
22
description: High-performance asynchronous interface for SQLite on Dart and Flutter.
3-
version: 0.11.7
3+
version: 0.11.8
44
repository: https://github.com/powersync-ja/sqlite_async.dart
55
environment:
66
sdk: ">=3.5.0 <4.0.0"

0 commit comments

Comments
 (0)