From aa9258e3af7bf2be561e05e53ab766838f61500d Mon Sep 17 00:00:00 2001 From: fbachus Date: Thu, 30 Jul 2026 15:11:04 +0200 Subject: [PATCH] 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 --- lib/main.dart | 2 +- lib/transport_helper.dart | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 134e900..c8eef6d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -517,7 +517,7 @@ class _JourneyOverviewPageState extends State { initState() async { super.initState(); // TODO: implement batch query to get a list (all) of journeys - //allJourneys = await Journey.dbGetAll(); + allJourneys = await Journey.dbGetAll(); } @override diff --git a/lib/transport_helper.dart b/lib/transport_helper.dart index 3967d87..d1548ba 100644 --- a/lib/transport_helper.dart +++ b/lib/transport_helper.dart @@ -220,6 +220,27 @@ class Journey { return route; } + /// gets routesegments and hands them to the Journey.fromMap factory, works async + static Future fromMapWrapper(Map journeyMap) async { + Future> 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> 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> journeys = Future.wait( + tmp.map((jour) => fromMapWrapper(jour)), + ); + return journeys; + } + static Future> _dbGetJourneySegments( int routeId, ) async { @@ -454,6 +475,7 @@ class Segment { """); } + //TODO: support batches static Future dbGet(int id) async { Database database = DbHelper.db; String vehicle = Vehicle.tableName; @@ -1149,4 +1171,4 @@ enum VehicleType { subway, regionalTrain, PLACEHOLDER, -} +} \ No newline at end of file