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

@@ -32,11 +32,26 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
}
/// Adds a new group with the given [id] and [name] to the database.
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
Future<void> addGroup(String id, String name) async {
await into(
groupTable,
).insert(GroupTableCompanion.insert(id: id, name: name));
/// This method also adds the group's members to the [PlayerGroupTable].
Future<void> addGroup(Group group) async {
await db.transaction(() async {
await into(
groupTable,
).insert(GroupTableCompanion.insert(id: group.id, name: group.name));
await db.batch(
(b) => b.insertAll(
db.playerGroupTable,
group.members
.map(
(member) => PlayerGroupTableCompanion.insert(
playerId: member.id,
groupId: group.id,
),
)
.toList(),
),
);
});
}
/// Deletes the group with the given [id] from the database.