Skip to content

Commit 4b56076

Browse files
committed
Allow transforming table updates from sqlite_async.
1 parent 8d65840 commit 4b56076

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

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+
- Allow transforming table updates from sqlite_async.
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/connection.dart

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,22 @@ import 'package:sqlite_async/sqlite_async.dart';
1515
class SqliteAsyncDriftConnection extends DatabaseConnection {
1616
late StreamSubscription _updateSubscription;
1717

18-
SqliteAsyncDriftConnection(SqliteConnection db, {bool logStatements = false})
19-
: super(SqliteAsyncQueryExecutor(db, logStatements: logStatements)) {
18+
SqliteAsyncDriftConnection(
19+
SqliteConnection db, {
20+
bool logStatements = false,
21+
Set<TableUpdate> Function(UpdateNotification)? transformTableUpdate,
22+
}) : super(SqliteAsyncQueryExecutor(db, logStatements: logStatements)) {
2023
_updateSubscription = (db as SqliteQueries).updates!.listen((event) {
21-
var setUpdates = <TableUpdate>{};
22-
for (var tableName in event.tables) {
23-
setUpdates.add(TableUpdate(tableName));
24+
final Set<TableUpdate> setUpdates;
25+
// This is useful to map local table names from PowerSync that are backed by a view name
26+
// which is the entity that the user interacts with.
27+
if (transformTableUpdate != null) {
28+
setUpdates = transformTableUpdate(event);
29+
} else {
30+
setUpdates = <TableUpdate>{};
31+
for (var tableName in event.tables) {
32+
setUpdates.add(TableUpdate(tableName));
33+
}
2434
}
2535
super.streamQueries.handleTableUpdates(setUpdates);
2636
});

packages/drift_sqlite_async/pubspec.yaml

Lines changed: 1 addition & 1 deletion
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.

0 commit comments

Comments
 (0)