| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- import 'package:objectbox/objectbox.dart';
- abstract class dbMgrBase<T> {
- /// The Store of this app.
- late final Store store;
- late final Box<T> objectBox;
- dbMgrBase(this.store) {
- objectBox = Box(store);
- }
- //
- bool isEmpty() => objectBox.isEmpty();
- //
- List<T> getAll() => objectBox.getAll();
- T get(int id) => objectBox.get(id)!;
- T? getFirst() => objectBox.query().build().findFirst();
- Future<List<T>> getAllAsync() => objectBox.getAllAsync();
- Stream<List<T>> getAllStream(QueryProperty<T, dynamic> orderProperty, {int orderFlags = 0}) {
- // Query for all tasks, sorted by their date.
- // https://docs.objectbox.io/queries
- final queryBuilder = objectBox.query().order(orderProperty, flags: orderFlags);
- // Build and watch the query,
- // set triggerImmediately to emit the query immediately on listen.
- return queryBuilder
- .watch(triggerImmediately: true)
- // Map it to a list of tasks to be used by a StreamBuilder.
- .map((query) => query.find());
- }
- int put(T obj) => objectBox.put(obj);
- Future<int>putAsync(T obj) => objectBox.putAsync(obj);
- Future<List<int>>putManyAsync(List<T> objects,
- {PutMode mode = PutMode.put}) => objectBox.putManyAsync(objects, mode: mode);
- void remove(int id) => objectBox.removeAsync(id);
- }
|