feat: games with match associations cant be deleted
This commit is contained in:
@@ -176,4 +176,25 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
||||
final rowsAffected = await query.go();
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// Retrieves all games with their respective match counts.
|
||||
/// Returns a list of tuples (Game, matchCount).
|
||||
Future<List<(Game, int)>> getGameUsage() async {
|
||||
final games = await getAllGames();
|
||||
|
||||
final results = <(Game, int)>[];
|
||||
|
||||
for (final game in games) {
|
||||
final matchCount =
|
||||
await (selectOnly(db.matchTable)
|
||||
..where(db.matchTable.gameId.equals(game.id))
|
||||
..addColumns([db.matchTable.id.count()]))
|
||||
.map((row) => row.read(db.matchTable.id.count()))
|
||||
.getSingle();
|
||||
|
||||
results.add((game, matchCount ?? 0));
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user