45 lines
1.1 KiB
Dart
45 lines
1.1 KiB
Dart
import 'package:diameter/main.dart';
|
|
import 'package:diameter/objectbox.g.dart';
|
|
|
|
@Entity(uid: 8812452529027052317)
|
|
class BolusProfile {
|
|
static final Box<BolusProfile> box = objectBox.store.box<BolusProfile>();
|
|
|
|
int id;
|
|
String name;
|
|
bool active;
|
|
String? notes;
|
|
|
|
BolusProfile({
|
|
this.id = 0,
|
|
this.name = '',
|
|
this.active = false,
|
|
this.notes,
|
|
});
|
|
|
|
static BolusProfile? get(int id) => box.get(id);
|
|
static List<BolusProfile> getAll() => box.getAll();
|
|
static void put(BolusProfile bolusProfile) => box.put(bolusProfile);
|
|
static void remove(int id) => box.remove(id);
|
|
|
|
static int activeCount() {
|
|
Query<BolusProfile> query =
|
|
box.query(BolusProfile_.active.equals(true)).build();
|
|
return query.find().length;
|
|
}
|
|
|
|
static void setAllInactive() {
|
|
box.putMany(box.getAll().map((element) {
|
|
element.active = false;
|
|
return element;
|
|
}).toList());
|
|
}
|
|
|
|
static BolusProfile? getActive() {
|
|
Query<BolusProfile> query =
|
|
box.query(BolusProfile_.active.equals(true)).build();
|
|
final result = query.find();
|
|
return result.length != 1 ? null : result.single;
|
|
}
|
|
}
|