Added missing methods and implemented tests

This commit is contained in:
2025-11-12 20:02:01 +01:00
parent 3f5a840675
commit 93a4ccaee0
11 changed files with 402 additions and 41 deletions

View File

@@ -57,13 +57,21 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
GameTableCompanion.insert(
id: game.id,
name: game.name,
winnerId: Value(game.winner),
winnerId: game.winner,
),
mode: InsertMode.insertOrReplace,
);
});
}
/// Deletes the game with the given [gameId] from the database.
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
Future<bool> deleteGame({required String gameId}) async {
final query = delete(gameTable)..where((g) => g.id.equals(gameId));
final rowsAffected = await query.go();
return rowsAffected > 0;
}
/// Retrieves the number of games in the database.
Future<int> getGameCount() async {
final count =
@@ -72,4 +80,12 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
.getSingle();
return count ?? 0;
}
/// Checks if a game with the given [gameId] exists in the database.
/// Returns `true` if the game exists, otherwise `false`.
Future<bool> gameExists({required String gameId}) async {
final query = select(gameTable)..where((g) => g.id.equals(gameId));
final result = await query.getSingleOrNull();
return result != null;
}
}