deleted games get ignored when includeDeleted is false

This commit is contained in:
gelbeinhalb
2026-05-12 20:30:46 +02:00
parent b3b3def07a
commit 36ad2ab446

View File

@@ -65,25 +65,40 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
/* Read */ /* Read */
/// Retrieves the total count of games in the database. /// Retrieves the total count of games in the database.
Future<int> getGameCount() async { /// By default, only returns non-deleted games.
final count = Future<int> getGameCount({bool includeDeleted = false}) async {
await (selectOnly(gameTable)..addColumns([gameTable.id.count()])) 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())) .map((row) => row.read(gameTable.id.count()))
.getSingle(); .getSingle();
return count ?? 0; return count ?? 0;
} }
/// Checks if a game with the given [gameId] exists in the database. /// 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. /// Returns `true` if the game exists, `false` otherwise.
Future<bool> gameExists({required String gameId}) async { Future<bool> gameExists({
required String gameId,
bool includeDeleted = false,
}) async {
final query = select(gameTable)..where((g) => g.id.equals(gameId)); final query = select(gameTable)..where((g) => g.id.equals(gameId));
if (!includeDeleted) {
query.where((g) => g.deleted.equals(false));
}
final result = await query.getSingleOrNull(); final result = await query.getSingleOrNull();
return result != null; return result != null;
} }
/// Retrieves all games from the database. /// Retrieves all games from the database.
Future<List<Game>> getAllGames() async { /// By default, only returns non-deleted games.
Future<List<Game>> getAllGames({bool includeDeleted = false}) async {
final query = select(gameTable); final query = select(gameTable);
if (!includeDeleted) {
query.where((g) => g.deleted.equals(false));
}
final result = await query.get(); final result = await query.get();
return result return result
.map( .map(
@@ -101,8 +116,15 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
} }
/// Retrieves a [Game] by its [gameId]. /// Retrieves a [Game] by its [gameId].
Future<Game> getGameById({required String gameId}) async { /// By default, only returns non-deleted games.
Future<Game> getGameById({
required String gameId,
bool includeDeleted = false,
}) async {
final query = select(gameTable)..where((g) => g.id.equals(gameId)); final query = select(gameTable)..where((g) => g.id.equals(gameId));
if (!includeDeleted) {
query.where((g) => g.deleted.equals(false));
}
final result = await query.getSingle(); final result = await query.getSingle();
return Game( return Game(
id: result.id, id: result.id,
@@ -196,9 +218,10 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
} }
/// Retrieves all games with their respective match counts. /// Retrieves all games with their respective match counts.
/// By default, only returns non-deleted games.
/// Returns a list of tuples (Game, matchCount). /// Returns a list of tuples (Game, matchCount).
Future<List<(Game, int)>> getGameUsage() async { Future<List<(Game, int)>> getGameUsage({bool includeDeleted = false}) async {
final games = await getAllGames(); final games = await getAllGames(includeDeleted: includeDeleted);
final results = <(Game, int)>[]; final results = <(Game, int)>[];