feat(transport_helper): add function to query multiple journeys

could query all, but the last 40 should be fine, no?
could raise to no limit, but should be done as generator for that
This commit is contained in:
fbachus
2026-07-30 15:11:04 +02:00
parent c313a94a10
commit aa9258e3af
2 changed files with 24 additions and 2 deletions
+23 -1
View File
@@ -220,6 +220,27 @@ class Journey {
return route;
}
/// gets routesegments and hands them to the Journey.fromMap factory, works async
static Future<Journey> fromMapWrapper(Map<String, Object?> journeyMap) async {
Future<List<Segment>> segs = _dbGetJourneySegments(journeyMap["id"] as int);
Journey res = Journey.fromMap(journeyMap, await segs);
return res;
}
// TODO: could make this a generator and use batched queries, probably
// query all journeys
// _dbGetJourneySegments -> give list of segments for each journey
// map all journeys
static Future<List<Journey>> dbGetAll({int num = 40, int offset = 0}) async {
//final batch = DbHelper.db.batch; // later
Database database = DbHelper.db;
var tmp = await database.query(tableName, limit: num, offset: offset);
Future<List<Journey>> journeys = Future.wait(
tmp.map((jour) => fromMapWrapper(jour)),
);
return journeys;
}
static Future<List<Segment>> _dbGetJourneySegments(
int routeId,
) async {
@@ -454,6 +475,7 @@ class Segment {
""");
}
//TODO: support batches
static Future<Segment> dbGet(int id) async {
Database database = DbHelper.db;
String vehicle = Vehicle.tableName;
@@ -1149,4 +1171,4 @@ enum VehicleType {
subway,
regionalTrain,
PLACEHOLDER,
}
}