Datenbankstruktur für Spiele #16
@@ -61,4 +61,13 @@ class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
|
|||||||
PlayerTableCompanion(name: Value(newName)),
|
PlayerTableCompanion(name: Value(newName)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Retrieves the total count of players in the database.
|
||||||
|
Future<int> getPlayerCount() async {
|
||||||
|
final count =
|
||||||
|
await (selectOnly(playerTable)..addColumns([playerTable.id.count()]))
|
||||||
|
.map((row) => row.read(playerTable.id.count()))
|
||||||
|
.getSingle();
|
||||||
|
return count ?? 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,4 +127,22 @@ void main() {
|
|||||||
final playerExists = result.members.any((p) => p.id == playerToRemove.id);
|
final playerExists = result.members.any((p) => p.id == playerToRemove.id);
|
||||||
expect(playerExists, false);
|
expect(playerExists, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('get group count works correctly', () async {
|
||||||
|
final initialCount = await database.groupDao.getGroupCount();
|
||||||
|
expect(initialCount, 0);
|
||||||
|
|
||||||
|
await database.groupDao.addGroup(group: testgroup);
|
||||||
|
|
||||||
|
final groupAdded = await database.groupDao.getGroupCount();
|
||||||
|
expect(groupAdded, 1);
|
||||||
|
|
||||||
|
final groupRemoved = await database.groupDao.deleteGroup(
|
||||||
|
groupId: testgroup.id,
|
||||||
|
);
|
||||||
|
expect(groupRemoved, true);
|
||||||
|
|
||||||
|
final finalCount = await database.groupDao.getGroupCount();
|
||||||
|
expect(finalCount, 0);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,5 +62,23 @@ void main() {
|
|||||||
);
|
);
|
||||||
expect(result.name, newPlayerName);
|
expect(result.name, newPlayerName);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('get player count works correctly', () async {
|
||||||
|
final initialCount = await database.playerDao.getPlayerCount();
|
||||||
|
expect(initialCount, 0);
|
||||||
|
|
||||||
|
await database.playerDao.addPlayer(player: testPlayer);
|
||||||
|
|
||||||
|
final playerAdded = await database.playerDao.getPlayerCount();
|
||||||
|
expect(playerAdded, 1);
|
||||||
|
|
||||||
|
final playerRemoved = await database.playerDao.deletePlayer(
|
||||||
|
playerId: testPlayer.id,
|
||||||
|
);
|
||||||
|
expect(playerRemoved, true);
|
||||||
|
|
||||||
|
final finalCount = await database.playerDao.getPlayerCount();
|
||||||
|
expect(finalCount, 0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user