From 36ad2ab446b87ba16ae9b5f428697ddbe0c27cb6 Mon Sep 17 00:00:00 2001 From: gelbeinhalb Date: Tue, 12 May 2026 20:30:46 +0200 Subject: [PATCH] deleted games get ignored when includeDeleted is false --- lib/data/dao/game_dao.dart | 43 +++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/lib/data/dao/game_dao.dart b/lib/data/dao/game_dao.dart index a4c2300..e8e2883 100644 --- a/lib/data/dao/game_dao.dart +++ b/lib/data/dao/game_dao.dart @@ -65,25 +65,40 @@ class GameDao extends DatabaseAccessor with _$GameDaoMixin { /* Read */ /// Retrieves the total count of games in the database. - Future getGameCount() async { - final count = - await (selectOnly(gameTable)..addColumns([gameTable.id.count()])) - .map((row) => row.read(gameTable.id.count())) - .getSingle(); + /// By default, only returns non-deleted games. + Future getGameCount({bool includeDeleted = false}) async { + final query = selectOnly(gameTable)..addColumns([gameTable.id.count()]); + if (!includeDeleted) { + query.where(gameTable.deleted.equals(false)); + } + final count = await query + .map((row) => row.read(gameTable.id.count())) + .getSingle(); return count ?? 0; } /// Checks if a game with the given [gameId] exists in the database. + /// By default, only returns non-deleted games. /// Returns `true` if the game exists, `false` otherwise. - Future gameExists({required String gameId}) async { + Future gameExists({ + required String gameId, + bool includeDeleted = false, + }) async { final query = select(gameTable)..where((g) => g.id.equals(gameId)); + if (!includeDeleted) { + query.where((g) => g.deleted.equals(false)); + } final result = await query.getSingleOrNull(); return result != null; } /// Retrieves all games from the database. - Future> getAllGames() async { + /// By default, only returns non-deleted games. + Future> getAllGames({bool includeDeleted = false}) async { final query = select(gameTable); + if (!includeDeleted) { + query.where((g) => g.deleted.equals(false)); + } final result = await query.get(); return result .map( @@ -101,8 +116,15 @@ class GameDao extends DatabaseAccessor with _$GameDaoMixin { } /// Retrieves a [Game] by its [gameId]. - Future getGameById({required String gameId}) async { + /// By default, only returns non-deleted games. + Future getGameById({ + required String gameId, + bool includeDeleted = false, + }) async { final query = select(gameTable)..where((g) => g.id.equals(gameId)); + if (!includeDeleted) { + query.where((g) => g.deleted.equals(false)); + } final result = await query.getSingle(); return Game( id: result.id, @@ -196,9 +218,10 @@ class GameDao extends DatabaseAccessor with _$GameDaoMixin { } /// Retrieves all games with their respective match counts. + /// By default, only returns non-deleted games. /// Returns a list of tuples (Game, matchCount). - Future> getGameUsage() async { - final games = await getAllGames(); + Future> getGameUsage({bool includeDeleted = false}) async { + final games = await getAllGames(includeDeleted: includeDeleted); final results = <(Game, int)>[];