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 */
/// Retrieves the total count of games in the database.
Future<int> 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<int> 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<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));
if (!includeDeleted) {
query.where((g) => g.deleted.equals(false));
}
final result = await query.getSingleOrNull();
return result != null;
}
/// 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);
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<AppDatabase> with _$GameDaoMixin {
}
/// 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));
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<AppDatabase> 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<List<(Game, int)>> getGameUsage() async {
final games = await getAllGames();
Future<List<(Game, int)>> getGameUsage({bool includeDeleted = false}) async {
final games = await getAllGames(includeDeleted: includeDeleted);
final results = <(Game, int)>[];