First version of retrieving a gamesession from the db

This commit is contained in:
2025-08-21 22:30:13 +02:00
parent 4901e27b90
commit 7a420e909a
28 changed files with 868 additions and 1175 deletions

View File

@@ -0,0 +1,38 @@
import 'package:cabo_counter/data/db/database.dart';
import 'package:cabo_counter/data/db/tables/player_table.dart';
import 'package:cabo_counter/data/dto/player.dart';
import 'package:drift/drift.dart';
part 'player_dao.g.dart';
@DriftAccessor(tables: [PlayerTable])
class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
PlayerDao(super.db);
/// Retrieves all players from a game by gameId
Future<List<Player>> getPlayersByGameId(String gameId) async {
final query = select(playerTable)
..where((tbl) => tbl.gameId.equals(gameId));
final playerResults = await query.get();
return playerResults.map((row) {
return Player(
playerId: row.playerId,
gameId: row.gameId,
name: row.name,
position: row.position,
totalScore: row.totalScore,
);
}).toList()
..sort((a, b) => a.position.compareTo(b.position));
}
/// Retrieves a players position by its id
Future<int> getPositionByPlayerId(String playerId) async {
final query = select(playerTable)
..where((tbl) => tbl.playerId.equals(playerId));
final result = await query.getSingle();
return result.position;
}
}