@@ -145,7 +145,7 @@ abstract class _BaseAdapter<T extends DataModelMixin<T>> with _Lifecycle {
145145 return result.map ((r) {
146146 final map = Map <String , dynamic >.from (jsonDecode (r['data' ]));
147147 return deserializeLocal (map,
148- key: r['key' ]. toString ( ).typifyWith (internalType));
148+ key: ( r['key' ] as int ).typifyWith (internalType));
149149 }).toList ();
150150 }
151151
@@ -236,7 +236,7 @@ abstract class _BaseAdapter<T extends DataModelMixin<T>> with _Lifecycle {
236236 final data = jsonEncode (map);
237237 final result = ps.select ([key, data]);
238238 savedKeys.add (
239- result.first['key' ]. toString ( ).typifyWith (adapter.internalType));
239+ ( result.first['key' ] as int ).typifyWith (adapter.internalType));
240240 }
241241 ps.dispose ();
242242 }
@@ -261,7 +261,7 @@ abstract class _BaseAdapter<T extends DataModelMixin<T>> with _Lifecycle {
261261
262262 /// Deletes models with [keys] from local storage.
263263 void deleteLocalByKeys (Iterable <String > keys, {bool notify = true }) {
264- final intKeys = keys.map ((k) => k.detypifyKey ()).toList ();
264+ final intKeys = keys.map ((k) => k.detypifyKey ()! ).toList ();
265265 db.execute (
266266 'DELETE FROM $internalType WHERE key IN (${keys .map ((_ ) => '?' ).join (', ' )})' ,
267267 intKeys);
@@ -272,14 +272,14 @@ abstract class _BaseAdapter<T extends DataModelMixin<T>> with _Lifecycle {
272272 }
273273
274274 /// Deletes all models of type [T] in local storage.
275+ ///
276+ /// Async in case some implementations need to remove files.
275277 Future <void > clearLocal ({bool notify = true }) async {
276- // print(db.select('SELECT name FROM sqlite_master WHERE type=?', ['table']));
277- // TODO should also clear edges?
278+ final _ = db.select ('DELETE FROM $internalType RETURNING key;' );
279+ final keys =
280+ _.map ((e) => (e['key' ] as int ).typifyWith (internalType)).toList ();
281+ await core.deleteKeys (keys);
278282
279- // leave async in case some impls need to remove files
280- for (final adapter in adapters.values) {
281- db.execute ('DELETE FROM ${adapter .internalType }' );
282- }
283283 if (notify) {
284284 core._notify ([internalType], type: DataGraphEventType .clear);
285285 }
@@ -296,7 +296,7 @@ abstract class _BaseAdapter<T extends DataModelMixin<T>> with _Lifecycle {
296296 final result =
297297 db.select ('SELECT key FROM _keys WHERE type = ?' , [internalType]);
298298 return result
299- .map ((r) => r['key' ]. toString ( ).typifyWith (internalType))
299+ .map ((r) => ( r['key' ] as int ).typifyWith (internalType))
300300 .toSet ();
301301 }
302302
0 commit comments