Skip to content

Commit 373d8b5

Browse files
committed
misc fixes
1 parent 90a4c07 commit 373d8b5

File tree

9 files changed

+24
-38
lines changed

9 files changed

+24
-38
lines changed

example/lib/main.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ void main() async {
1919
localStorageProvider.overrideWith(
2020
(ref) => LocalStorage(
2121
baseDirFn: () => _dir.path,
22-
encryptionKey: 'blah',
2322
clear: LocalStorageClearStrategy.always,
2423
),
2524
),
@@ -39,7 +38,7 @@ void main() async {
3938
final user2 = container.users.findOneLocalById(1);
4039

4140
assert(user.name == user2!.name);
42-
print(user.tasks.length); // TODO fix
41+
assert(user.tasks.length == 3);
4342
} finally {
4443
await container.read(localStorageProvider).destroy();
4544
}

example/lib/main.data.dart

Lines changed: 10 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/lib/models/task.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Task extends DataModel<Task> {
1313
final int? id;
1414
final String title;
1515
final bool completed;
16+
@JsonKey(name: 'userId')
1617
final BelongsTo<User>? user;
1718

1819
Task({this.id, required this.title, this.completed = false, this.user});

example/lib/models/task.g.dart

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/adapter/remote_adapter.dart

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,6 @@ mixin _RemoteAdapter<T extends DataModelMixin<T>> on _SerializationAdapter<T> {
498498
return label.model as R?;
499499
}
500500

501-
print('1');
502501
final data = await deserialize(body as Map<String, dynamic>,
503502
key: label.model!._key);
504503
final model = data.model!;
@@ -507,7 +506,6 @@ mixin _RemoteAdapter<T extends DataModelMixin<T>> on _SerializationAdapter<T> {
507506
if (model._key != label.model!._key) {
508507
deleteLocalByKeys({label.model!._key!});
509508
}
510-
print('2');
511509
model.saveLocal();
512510

513511
log(label, 'saved in local storage and remote');
@@ -532,7 +530,6 @@ mixin _RemoteAdapter<T extends DataModelMixin<T>> on _SerializationAdapter<T> {
532530
return response.body as R?;
533531
}
534532

535-
// TODO test: not properly deserializing findAll with relationship references (see example app)
536533
final deserialized = await deserialize(body);
537534

538535
if (isFindAll || (isCustom && deserialized.model == null)) {
@@ -584,10 +581,7 @@ mixin _RemoteAdapter<T extends DataModelMixin<T>> on _SerializationAdapter<T> {
584581
Future<void> _saveDeserialized(DeserializedData deserialized) async {
585582
final models = [...deserialized.models, ...deserialized.included];
586583
if (models.isEmpty) return;
587-
await logTimeAsync('[_saveDeserialized] writing ${models.length} models',
588-
() async {
589-
await saveManyLocal(models.cast());
590-
});
584+
await saveManyLocal(models.cast());
591585
}
592586

593587
/// Returns URL for [findAll]. Defaults to [type].

lib/src/adapter/serialization_adapter.dart

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@ mixin _SerializationAdapter<T extends DataModelMixin<T>> on _BaseAdapter<T> {
2424
return map;
2525
}
2626

27-
// Future<DeserializedData<T>> deserialize(Object? data,
28-
// {String? key, async = true}) async {
29-
// final z = await runInIsolate((container) async {
30-
31-
// return <DataModelMixin>[];
32-
// });
33-
// return DeserializedData([]);
34-
// }
35-
3627
(List<DataModelMixin>, List<DataModelMixin>) _deserialize(
3728
Adapter adapter, Object? data,
3829
{String? key}) {
@@ -78,9 +69,9 @@ mixin _SerializationAdapter<T extends DataModelMixin<T>> on _BaseAdapter<T> {
7869
}
7970

8071
if (metadata.kind == 'BelongsTo') {
81-
// NOTE: when _process was async, a sqlite bug
82-
// appears when awaiting it (db turns to inMemory and closed)
83-
// and leaving everything sync works for now
72+
// NOTE: when _processIdAndAddInclude was async, a sqlite bug
73+
// appeared when awaiting it (db turns to inMemory and closed)
74+
// so leaving everything sync works for now
8475
final key = _processIdAndAddInclude(mapIn[mapKey], relType);
8576
if (key != null) mapOut[mapKey] = key;
8677
}

lib/src/model/relationship/relationship.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ sealed class Relationship<E extends DataModelMixin<E>, N> with EquatableMixin {
9999

100100
if (order == -1) {
101101
db.execute(
102-
'UPDATE _edges SET dest = ? WHERE key_ = ? AND name_ = ? AND _key = ?',
102+
'UPDATE _edges SET _key = ? WHERE key_ = ? AND name_ = ? AND _key = ?',
103103
args);
104104
} else {
105105
db.execute(

lib/src/storage/local_storage.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ part of flutter_data;
33
class LocalStorage {
44
LocalStorage({
55
required this.baseDirFn,
6-
this.encryptionKey,
76
LocalStorageClearStrategy? clear,
87
}) : clear = clear ?? LocalStorageClearStrategy.never;
98

109
var isInitialized = false;
1110

12-
final String? encryptionKey;
1311
final FutureOr<String> Function() baseDirFn;
1412
final LocalStorageClearStrategy clear;
1513

test/core/core_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ void main() async {
6565
familias.add(familia);
6666
}
6767

68-
await logTimeAsync('bulk save', () async {
69-
await container.familia.saveManyLocal(familias);
70-
});
68+
await container.familia.saveManyLocal(familias);
7169

7270
expect(container.familia.countLocal, length);
7371
});

0 commit comments

Comments
 (0)