Skip to content

Commit d7376cf

Browse files
committed
findManyLocalByIds
1 parent 0321847 commit d7376cf

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version: 1.0.0+1
44
publish_to: none
55

66
environment:
7-
sdk: ">=2.17.1 <3.0.0"
7+
sdk: ">=3.1.0 <4.0.0"
88

99
dependencies:
1010
flutter_data:

lib/src/adapter/adapter.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ abstract class _BaseAdapter<T extends DataModelMixin<T>> with _Lifecycle {
6464
/// Give access to the dependency injection system
6565
@nonVirtual
6666
Ref get ref => _ref!;
67+
bool inIsolate = false;
6768

6869
@visibleForTesting
6970
@protected
@@ -101,10 +102,12 @@ abstract class _BaseAdapter<T extends DataModelMixin<T>> with _Lifecycle {
101102

102103
@mustCallSuper
103104
@nonVirtual
104-
Future<Adapter<T>> initialize({required Ref ref}) async {
105+
Future<Adapter<T>> initialize(
106+
{required Ref ref, bool inIsolate = false}) async {
105107
if (isInitialized) return this as Adapter<T>;
106108

107109
_ref = ref;
110+
this.inIsolate = inIsolate;
108111

109112
// hook for clients
110113
await onInitialized();
@@ -140,6 +143,15 @@ abstract class _BaseAdapter<T extends DataModelMixin<T>> with _Lifecycle {
140143
return deserializeFromResult(result);
141144
}
142145

146+
// TODO test
147+
/// Finds many models of type [T] by [ids] in local storage.
148+
List<T> findManyLocalByIds(Iterable<Object> ids) {
149+
final result = db.select(
150+
'SELECT $internalType.key, data FROM $internalType JOIN _keys ON _keys.key = $internalType.key WHERE id IN (${ids.map((_) => '?').join(', ')})',
151+
ids.map((id) => id.toString()).toList());
152+
return deserializeFromResult(result);
153+
}
154+
143155
@protected
144156
List<T> deserializeFromResult(ResultSet result) {
145157
return result.map((r) {
@@ -220,7 +232,7 @@ abstract class _BaseAdapter<T extends DataModelMixin<T>> with _Lifecycle {
220232
// initialize and register
221233
for (final adapter in _internalAdaptersMap!.values) {
222234
adapter.dispose();
223-
await adapter.initialize(ref: _ref);
235+
await adapter.initialize(ref: _ref, inIsolate: true);
224236
}
225237

226238
final adapter = internalProvidersMap[_internalType]!;

0 commit comments

Comments
 (0)