Skip to content

Commit

Permalink
fix issue #386 add experimental reload feature
Browse files Browse the repository at this point in the history
  • Loading branch information
alextekartik committed Aug 19, 2024
1 parent c7fe133 commit 585d8fe
Show file tree
Hide file tree
Showing 14 changed files with 394 additions and 198 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ test_out

# local overrides
pubspec_overrides.yaml
# tmp root project to workaround analyze issue in 3.5
/pubspec.yaml
/pubspec.lock
13 changes: 13 additions & 0 deletions sembast/lib/src/api/record_snapshot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,16 @@ abstract class RecordSnapshot<K extends Key?, V extends Value?> {
/// Cast if needed
RecordSnapshot<RK, RV> cast<RK extends Key?, RV extends Value?>();
}

/// Extension on iterable of record snapshot
extension RecordSnapshotIterableExtension<K extends Key?, V extends Value?>
on Iterable<RecordSnapshot<K, V>> {
/// Keys
Iterable<K> get keys => map((e) => e.key);

/// Values
Iterable<V> get values => map((e) => e.value);

/// Key value pairs
Iterable<(K, V)> get keysAndValues => map((e) => (e.key, e.value));
}
3 changes: 2 additions & 1 deletion sembast/lib/src/api/sembast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export 'package:sembast/src/api/finder.dart';
export 'package:sembast/src/api/query_ref.dart';
export 'package:sembast/src/api/record_ref.dart' show RecordRef;
export 'package:sembast/src/type.dart' show RecordKeyBase, RecordValueBase;
export 'package:sembast/src/api/record_snapshot.dart';
export 'package:sembast/src/api/record_snapshot.dart'
show RecordSnapshot, RecordSnapshotIterableExtension;
export 'package:sembast/src/api/records_ref.dart';
export 'package:sembast/src/api/sort_order.dart';
export 'package:sembast/src/api/store_ref.dart';
Expand Down
14 changes: 14 additions & 0 deletions sembast/lib/src/api/v2/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,18 @@ extension DatabaseExtension on Database {
/// On sembast_web and sembast_sqflite, data will be
/// read again (incrementally or not) to handle external changes.
Future<void> checkForChanges() => (this as SembastDatabase).checkForChanges();

/// Warning: unsafe.
///
/// On sembast io, the file will be reloaded. Unpredictable behavior if a write
/// happens at the same time. The database is closed and re-opened.
/// So any pending listeners are lost.
Future<void> reOpen() => (this as SembastDatabase).reOpen();

/// Warning: unsafe.
///
/// On sembast io, the file will be reloaded. Unpredictable behavior if a write
/// happens at the same time. The database if not closed and existing listeners
/// remain.
Future<void> reload() => (this as SembastDatabase).reload();
}
Loading

0 comments on commit 585d8fe

Please sign in to comment.