getLocationsByDateRange method
Implementation
Future<List<LocationDataModel>> getLocationsByDateRange({
DateTime? from,
DateTime? to,
int limit = 500,
}) async {
final db = await database;
String? where;
List<Object?>? whereArgs;
if (from != null && to != null) {
where = 'timestamp >= ? AND timestamp <= ?';
whereArgs = [from.toIso8601String(), to.toIso8601String()];
} else if (from != null) {
where = 'timestamp >= ?';
whereArgs = [from.toIso8601String()];
} else if (to != null) {
where = 'timestamp <= ?';
whereArgs = [to.toIso8601String()];
}
final maps = await db.query(
'locations',
where: where,
whereArgs: whereArgs,
limit: limit,
orderBy: 'timestamp ASC',
);
return maps.map(_rowToLocation).toList();
}