Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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/drift_sqlite_async/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.4

- Allow transforming table updates from sqlite_async.

## 0.2.3+1

- Update a dependency to the latest release.
Expand Down
20 changes: 15 additions & 5 deletions packages/drift_sqlite_async/lib/src/connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,22 @@ import 'package:sqlite_async/sqlite_async.dart';
class SqliteAsyncDriftConnection extends DatabaseConnection {
late StreamSubscription _updateSubscription;

SqliteAsyncDriftConnection(SqliteConnection db, {bool logStatements = false})
: super(SqliteAsyncQueryExecutor(db, logStatements: logStatements)) {
SqliteAsyncDriftConnection(
SqliteConnection db, {
bool logStatements = false,
Set<TableUpdate> Function(UpdateNotification)? transformTableUpdates,
}) : super(SqliteAsyncQueryExecutor(db, logStatements: logStatements)) {
_updateSubscription = (db as SqliteQueries).updates!.listen((event) {
var setUpdates = <TableUpdate>{};
for (var tableName in event.tables) {
setUpdates.add(TableUpdate(tableName));
final Set<TableUpdate> setUpdates;
// This is useful to map local table names from PowerSync that are backed by a view name
// which is the entity that the user interacts with.
if (transformTableUpdates != null) {
setUpdates = transformTableUpdates(event);
} else {
setUpdates = <TableUpdate>{};
for (var tableName in event.tables) {
setUpdates.add(TableUpdate(tableName));
}
}
super.streamQueries.handleTableUpdates(setUpdates);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/drift_sqlite_async/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: drift_sqlite_async
version: 0.2.3+1
version: 0.2.4
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.
Expand Down