Added methods for inserting games and groups into the db

This commit is contained in:
2025-11-12 12:04:33 +01:00
parent b6700bafd9
commit d07943add9
5 changed files with 58 additions and 5 deletions

View File

@@ -41,6 +41,27 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
);
}
Future<void> addGame(Game game) async {
await db.transaction(() async {
for (final p in game.players ?? []) {
await db.playerDao.addPlayer(p);
await db.playerGameDao.addPlayerToGame(game.id, p.id);
}
if (game.group != null) {
await db.groupDao.addGroup(game.group!);
await db.groupGameDao.addGroupToGame(game.id, game.group!.id);
}
await into(gameTable).insert(
GameTableCompanion.insert(
id: game.id,
name: game.name,
winnerId: Value(game.winner),
),
mode: InsertMode.insertOrReplace,
);
});
}
/// Retrieves the number of games in the database.
Future<int> getGameCount() async {
final count =