Line data Source code
1 : part of flutter_data; 2 : 3 : /// An adapter interface to access local storage 4 : /// 5 : /// See also: [HiveLocalAdapter] 6 : abstract class LocalAdapter<T extends DataModel<T>> 7 : with _Lifecycle<LocalAdapter<T>> { 8 1 : @protected 9 : LocalAdapter(this.graph); 10 : 11 : @protected 12 : final GraphNotifier graph; 13 : 14 : @override 15 : @mustCallSuper 16 1 : FutureOr<LocalAdapter<T>> initialize() async { 17 2 : await super.initialize(); 18 3 : await graph.initialize(); 19 : return this; 20 : } 21 : 22 : @override 23 : @mustCallSuper 24 1 : Future<void> dispose() async { 25 2 : await super.dispose(); 26 3 : await graph.dispose(); 27 : } 28 : 29 : // protected API 30 : 31 : /// Returns all models of type [T] in local storage. 32 : @protected 33 : @visibleForTesting 34 : List<T> findAll(); 35 : 36 : /// Finds model of type [T] by [key] in local storage. 37 : @protected 38 : @visibleForTesting 39 : T findOne(String key); 40 : 41 : /// Saves model of type [T] with [key] in local storage. 42 : /// 43 : /// By default notifies this modification to the associated [GraphNotifier]. 44 : @protected 45 : @visibleForTesting 46 : Future<void> save(String key, T model, {bool notify = true}); 47 : 48 : /// Deletes model of type [T] with [key] from local storage. 49 : /// 50 : /// By default notifies this modification to the associated [GraphNotifier]. 51 : @protected 52 : @visibleForTesting 53 : Future<void> delete(String key); 54 : 55 : /// Deletes all models of type [T] in local storage. 56 : @protected 57 : @visibleForTesting 58 : Future<void> clear(); 59 : 60 : // public abstract methods 61 : 62 : Map<String, dynamic> serialize(T model); 63 : 64 : T deserialize(Map<String, dynamic> map); 65 : 66 : Map<String, Map<String, Object>> relationshipsFor([T model]); 67 : }