test(mobile): store (#16243)
Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:immich_mobile/domain/interfaces/db.interface.dart';
|
||||
import 'package:immich_mobile/domain/models/store.model.dart';
|
||||
|
||||
abstract interface class IStoreRepository {
|
||||
abstract interface class IStoreRepository implements IDatabaseRepository {
|
||||
Future<bool> insert<T>(StoreKey<T> key, T value);
|
||||
|
||||
Future<T?> tryGet<T>(StoreKey<T> key);
|
||||
|
||||
@@ -77,4 +77,23 @@ class StoreUpdateEvent<T> {
|
||||
final T? value;
|
||||
|
||||
const StoreUpdateEvent(this.key, this.value);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '''
|
||||
StoreUpdateEvent: {
|
||||
key: $key,
|
||||
value: ${value ?? '<NA>'},
|
||||
}''';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(covariant StoreUpdateEvent<T> other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other.key == key && other.value == value;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => key.hashCode ^ value.hashCode;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ class IsarStoreRepository extends IsarDatabaseRepository
|
||||
|
||||
@override
|
||||
Stream<StoreUpdateEvent> watchAll() {
|
||||
return _db.storeValues.where().watch().asyncExpand(
|
||||
return _db.storeValues.where().watch(fireImmediately: true).asyncExpand(
|
||||
(entities) =>
|
||||
Stream.fromFutures(entities.map((e) async => _toUpdateEvent(e))),
|
||||
);
|
||||
@@ -86,17 +86,11 @@ class IsarStoreRepository extends IsarDatabaseRepository
|
||||
final (int? intValue, String? strValue) = switch (key.type) {
|
||||
const (int) => (value as int, null),
|
||||
const (String) => (null, value as String),
|
||||
const (bool) => (
|
||||
(value as bool) ? 1 : 0,
|
||||
null,
|
||||
),
|
||||
const (DateTime) => (
|
||||
(value as DateTime).millisecondsSinceEpoch,
|
||||
null,
|
||||
),
|
||||
const (bool) => ((value as bool) ? 1 : 0, null),
|
||||
const (DateTime) => ((value as DateTime).millisecondsSinceEpoch, null),
|
||||
const (User) => (
|
||||
(await UserRepository(_db).update(value as User)).isarId,
|
||||
null
|
||||
null,
|
||||
),
|
||||
_ => throw UnsupportedError(
|
||||
"Unsupported primitive type: ${key.type} for key: ${key.name}",
|
||||
|
||||
Reference in New Issue
Block a user