Renamed folder to "models"
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
import 'package:tallee/data/db/database.dart';
|
||||
import 'package:tallee/data/db/tables/game_table.dart';
|
||||
import 'package:tallee/data/dto/game.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
import 'package:tallee/data/models/game.dart';
|
||||
|
||||
part 'game_dao.g.dart';
|
||||
|
||||
@@ -111,14 +111,20 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
||||
}
|
||||
|
||||
/// Updates the name of the game with the given [gameId] to [newName].
|
||||
Future<void> updateGameName({required String gameId, required String newName}) async {
|
||||
await (update(
|
||||
gameTable,
|
||||
)..where((g) => g.id.equals(gameId))).write(GameTableCompanion(name: Value(newName)));
|
||||
Future<void> updateGameName({
|
||||
required String gameId,
|
||||
required String newName,
|
||||
}) async {
|
||||
await (update(gameTable)..where((g) => g.id.equals(gameId))).write(
|
||||
GameTableCompanion(name: Value(newName)),
|
||||
);
|
||||
}
|
||||
|
||||
/// Updates the ruleset of the game with the given [gameId].
|
||||
Future<void> updateGameRuleset({required String gameId, required Ruleset newRuleset}) async {
|
||||
Future<void> updateGameRuleset({
|
||||
required String gameId,
|
||||
required Ruleset newRuleset,
|
||||
}) async {
|
||||
await (update(gameTable)..where((g) => g.id.equals(gameId))).write(
|
||||
GameTableCompanion(ruleset: Value(newRuleset.name)),
|
||||
);
|
||||
@@ -135,24 +141,31 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
||||
}
|
||||
|
||||
/// Updates the color of the game with the given [gameId].
|
||||
Future<void> updateGameColor({required String gameId, required GameColor newColor}) async {
|
||||
await (update(
|
||||
gameTable,
|
||||
)..where((g) => g.id.equals(gameId))).write(GameTableCompanion(color: Value(newColor.name)));
|
||||
Future<void> updateGameColor({
|
||||
required String gameId,
|
||||
required GameColor newColor,
|
||||
}) async {
|
||||
await (update(gameTable)..where((g) => g.id.equals(gameId))).write(
|
||||
GameTableCompanion(color: Value(newColor.name)),
|
||||
);
|
||||
}
|
||||
|
||||
/// Updates the icon of the game with the given [gameId].
|
||||
Future<void> updateGameIcon({required String gameId, required String newIcon}) async {
|
||||
await (update(
|
||||
gameTable,
|
||||
)..where((g) => g.id.equals(gameId))).write(GameTableCompanion(icon: Value(newIcon)));
|
||||
Future<void> updateGameIcon({
|
||||
required String gameId,
|
||||
required String newIcon,
|
||||
}) async {
|
||||
await (update(gameTable)..where((g) => g.id.equals(gameId))).write(
|
||||
GameTableCompanion(icon: Value(newIcon)),
|
||||
);
|
||||
}
|
||||
|
||||
/// Retrieves the total count of games in the database.
|
||||
Future<int> getGameCount() async {
|
||||
final count = await (selectOnly(
|
||||
gameTable,
|
||||
)..addColumns([gameTable.id.count()])).map((row) => row.read(gameTable.id.count())).getSingle();
|
||||
final count =
|
||||
await (selectOnly(gameTable)..addColumns([gameTable.id.count()]))
|
||||
.map((row) => row.read(gameTable.id.count()))
|
||||
.getSingle();
|
||||
return count ?? 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,4 +5,12 @@ part of 'game_dao.dart';
|
||||
// ignore_for_file: type=lint
|
||||
mixin _$GameDaoMixin on DatabaseAccessor<AppDatabase> {
|
||||
$GameTableTable get gameTable => attachedDatabase.gameTable;
|
||||
GameDaoManager get managers => GameDaoManager(this);
|
||||
}
|
||||
|
||||
class GameDaoManager {
|
||||
final _$GameDaoMixin _db;
|
||||
GameDaoManager(this._db);
|
||||
$$GameTableTableTableManager get gameTable =>
|
||||
$$GameTableTableTableManager(_db.attachedDatabase, _db.gameTable);
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ import 'package:tallee/data/db/database.dart';
|
||||
import 'package:tallee/data/db/tables/group_table.dart';
|
||||
import 'package:tallee/data/db/tables/match_table.dart';
|
||||
import 'package:tallee/data/db/tables/player_group_table.dart';
|
||||
import 'package:tallee/data/dto/group.dart';
|
||||
import 'package:tallee/data/dto/player.dart';
|
||||
import 'package:tallee/data/models/group.dart';
|
||||
import 'package:tallee/data/models/player.dart';
|
||||
|
||||
part 'group_dao.g.dart';
|
||||
|
||||
|
||||
@@ -10,4 +10,23 @@ mixin _$GroupDaoMixin on DatabaseAccessor<AppDatabase> {
|
||||
attachedDatabase.playerGroupTable;
|
||||
$GameTableTable get gameTable => attachedDatabase.gameTable;
|
||||
$MatchTableTable get matchTable => attachedDatabase.matchTable;
|
||||
GroupDaoManager get managers => GroupDaoManager(this);
|
||||
}
|
||||
|
||||
class GroupDaoManager {
|
||||
final _$GroupDaoMixin _db;
|
||||
GroupDaoManager(this._db);
|
||||
$$GroupTableTableTableManager get groupTable =>
|
||||
$$GroupTableTableTableManager(_db.attachedDatabase, _db.groupTable);
|
||||
$$PlayerTableTableTableManager get playerTable =>
|
||||
$$PlayerTableTableTableManager(_db.attachedDatabase, _db.playerTable);
|
||||
$$PlayerGroupTableTableTableManager get playerGroupTable =>
|
||||
$$PlayerGroupTableTableTableManager(
|
||||
_db.attachedDatabase,
|
||||
_db.playerGroupTable,
|
||||
);
|
||||
$$GameTableTableTableManager get gameTable =>
|
||||
$$GameTableTableTableManager(_db.attachedDatabase, _db.gameTable);
|
||||
$$MatchTableTableTableManager get matchTable =>
|
||||
$$MatchTableTableTableManager(_db.attachedDatabase, _db.matchTable);
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@ import 'package:tallee/data/db/tables/game_table.dart';
|
||||
import 'package:tallee/data/db/tables/group_table.dart';
|
||||
import 'package:tallee/data/db/tables/match_table.dart';
|
||||
import 'package:tallee/data/db/tables/player_match_table.dart';
|
||||
import 'package:tallee/data/dto/game.dart';
|
||||
import 'package:tallee/data/dto/group.dart';
|
||||
import 'package:tallee/data/dto/match.dart';
|
||||
import 'package:tallee/data/dto/player.dart';
|
||||
import 'package:tallee/data/models/game.dart';
|
||||
import 'package:tallee/data/models/group.dart';
|
||||
import 'package:tallee/data/models/match.dart';
|
||||
import 'package:tallee/data/models/player.dart';
|
||||
|
||||
part 'match_dao.g.dart';
|
||||
|
||||
|
||||
@@ -11,4 +11,25 @@ mixin _$MatchDaoMixin on DatabaseAccessor<AppDatabase> {
|
||||
$TeamTableTable get teamTable => attachedDatabase.teamTable;
|
||||
$PlayerMatchTableTable get playerMatchTable =>
|
||||
attachedDatabase.playerMatchTable;
|
||||
MatchDaoManager get managers => MatchDaoManager(this);
|
||||
}
|
||||
|
||||
class MatchDaoManager {
|
||||
final _$MatchDaoMixin _db;
|
||||
MatchDaoManager(this._db);
|
||||
$$GameTableTableTableManager get gameTable =>
|
||||
$$GameTableTableTableManager(_db.attachedDatabase, _db.gameTable);
|
||||
$$GroupTableTableTableManager get groupTable =>
|
||||
$$GroupTableTableTableManager(_db.attachedDatabase, _db.groupTable);
|
||||
$$MatchTableTableTableManager get matchTable =>
|
||||
$$MatchTableTableTableManager(_db.attachedDatabase, _db.matchTable);
|
||||
$$PlayerTableTableTableManager get playerTable =>
|
||||
$$PlayerTableTableTableManager(_db.attachedDatabase, _db.playerTable);
|
||||
$$TeamTableTableTableManager get teamTable =>
|
||||
$$TeamTableTableTableManager(_db.attachedDatabase, _db.teamTable);
|
||||
$$PlayerMatchTableTableTableManager get playerMatchTable =>
|
||||
$$PlayerMatchTableTableTableManager(
|
||||
_db.attachedDatabase,
|
||||
_db.playerMatchTable,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:tallee/data/db/database.dart';
|
||||
import 'package:tallee/data/db/tables/player_table.dart';
|
||||
import 'package:tallee/data/dto/player.dart';
|
||||
import 'package:tallee/data/models/player.dart';
|
||||
|
||||
part 'player_dao.g.dart';
|
||||
|
||||
|
||||
@@ -5,4 +5,12 @@ part of 'player_dao.dart';
|
||||
// ignore_for_file: type=lint
|
||||
mixin _$PlayerDaoMixin on DatabaseAccessor<AppDatabase> {
|
||||
$PlayerTableTable get playerTable => attachedDatabase.playerTable;
|
||||
PlayerDaoManager get managers => PlayerDaoManager(this);
|
||||
}
|
||||
|
||||
class PlayerDaoManager {
|
||||
final _$PlayerDaoMixin _db;
|
||||
PlayerDaoManager(this._db);
|
||||
$$PlayerTableTableTableManager get playerTable =>
|
||||
$$PlayerTableTableTableManager(_db.attachedDatabase, _db.playerTable);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import 'package:drift/drift.dart';
|
||||
import 'package:tallee/data/db/database.dart';
|
||||
import 'package:tallee/data/db/tables/player_group_table.dart';
|
||||
import 'package:tallee/data/db/tables/player_table.dart';
|
||||
import 'package:tallee/data/dto/player.dart';
|
||||
import 'package:tallee/data/models/player.dart';
|
||||
|
||||
part 'player_group_dao.g.dart';
|
||||
|
||||
|
||||
@@ -8,4 +8,19 @@ mixin _$PlayerGroupDaoMixin on DatabaseAccessor<AppDatabase> {
|
||||
$GroupTableTable get groupTable => attachedDatabase.groupTable;
|
||||
$PlayerGroupTableTable get playerGroupTable =>
|
||||
attachedDatabase.playerGroupTable;
|
||||
PlayerGroupDaoManager get managers => PlayerGroupDaoManager(this);
|
||||
}
|
||||
|
||||
class PlayerGroupDaoManager {
|
||||
final _$PlayerGroupDaoMixin _db;
|
||||
PlayerGroupDaoManager(this._db);
|
||||
$$PlayerTableTableTableManager get playerTable =>
|
||||
$$PlayerTableTableTableManager(_db.attachedDatabase, _db.playerTable);
|
||||
$$GroupTableTableTableManager get groupTable =>
|
||||
$$GroupTableTableTableManager(_db.attachedDatabase, _db.groupTable);
|
||||
$$PlayerGroupTableTableTableManager get playerGroupTable =>
|
||||
$$PlayerGroupTableTableTableManager(
|
||||
_db.attachedDatabase,
|
||||
_db.playerGroupTable,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import 'package:drift/drift.dart';
|
||||
import 'package:tallee/data/db/database.dart';
|
||||
import 'package:tallee/data/db/tables/player_match_table.dart';
|
||||
import 'package:tallee/data/db/tables/team_table.dart';
|
||||
import 'package:tallee/data/dto/player.dart';
|
||||
import 'package:tallee/data/models/player.dart';
|
||||
|
||||
part 'player_match_dao.g.dart';
|
||||
|
||||
@@ -40,7 +40,7 @@ class PlayerMatchDao extends DatabaseAccessor<AppDatabase>
|
||||
if (result.isEmpty) return null;
|
||||
|
||||
final futures = result.map(
|
||||
(row) => db.playerDao.getPlayerById(playerId: row.playerId),
|
||||
(row) => db.playerDao.getPlayerById(playerId: row.playerId),
|
||||
);
|
||||
final players = await Future.wait(futures);
|
||||
return players;
|
||||
@@ -52,11 +52,11 @@ class PlayerMatchDao extends DatabaseAccessor<AppDatabase>
|
||||
required String matchId,
|
||||
required String playerId,
|
||||
}) async {
|
||||
final result = await (select(playerMatchTable)
|
||||
..where(
|
||||
(p) => p.matchId.equals(matchId) & p.playerId.equals(playerId),
|
||||
))
|
||||
.getSingleOrNull();
|
||||
final result =
|
||||
await (select(playerMatchTable)..where(
|
||||
(p) => p.matchId.equals(matchId) & p.playerId.equals(playerId),
|
||||
))
|
||||
.getSingleOrNull();
|
||||
return result?.score;
|
||||
}
|
||||
|
||||
@@ -67,11 +67,11 @@ class PlayerMatchDao extends DatabaseAccessor<AppDatabase>
|
||||
required String playerId,
|
||||
required int newScore,
|
||||
}) async {
|
||||
final rowsAffected = await (update(playerMatchTable)
|
||||
..where(
|
||||
(p) => p.matchId.equals(matchId) & p.playerId.equals(playerId),
|
||||
))
|
||||
.write(PlayerMatchTableCompanion(score: Value(newScore)));
|
||||
final rowsAffected =
|
||||
await (update(playerMatchTable)..where(
|
||||
(p) => p.matchId.equals(matchId) & p.playerId.equals(playerId),
|
||||
))
|
||||
.write(PlayerMatchTableCompanion(score: Value(newScore)));
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
@@ -82,11 +82,11 @@ class PlayerMatchDao extends DatabaseAccessor<AppDatabase>
|
||||
required String playerId,
|
||||
required String? teamId,
|
||||
}) async {
|
||||
final rowsAffected = await (update(playerMatchTable)
|
||||
..where(
|
||||
(p) => p.matchId.equals(matchId) & p.playerId.equals(playerId),
|
||||
))
|
||||
.write(PlayerMatchTableCompanion(teamId: Value(teamId)));
|
||||
final rowsAffected =
|
||||
await (update(playerMatchTable)..where(
|
||||
(p) => p.matchId.equals(matchId) & p.playerId.equals(playerId),
|
||||
))
|
||||
.write(PlayerMatchTableCompanion(teamId: Value(teamId)));
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
@@ -94,11 +94,11 @@ class PlayerMatchDao extends DatabaseAccessor<AppDatabase>
|
||||
/// Returns `true` if there are players, otherwise `false`.
|
||||
Future<bool> matchHasPlayers({required String matchId}) async {
|
||||
final count =
|
||||
await (selectOnly(playerMatchTable)
|
||||
..where(playerMatchTable.matchId.equals(matchId))
|
||||
..addColumns([playerMatchTable.playerId.count()]))
|
||||
.map((row) => row.read(playerMatchTable.playerId.count()))
|
||||
.getSingle();
|
||||
await (selectOnly(playerMatchTable)
|
||||
..where(playerMatchTable.matchId.equals(matchId))
|
||||
..addColumns([playerMatchTable.playerId.count()]))
|
||||
.map((row) => row.read(playerMatchTable.playerId.count()))
|
||||
.getSingle();
|
||||
return (count ?? 0) > 0;
|
||||
}
|
||||
|
||||
@@ -109,12 +109,12 @@ class PlayerMatchDao extends DatabaseAccessor<AppDatabase>
|
||||
required String playerId,
|
||||
}) async {
|
||||
final count =
|
||||
await (selectOnly(playerMatchTable)
|
||||
..where(playerMatchTable.matchId.equals(matchId))
|
||||
..where(playerMatchTable.playerId.equals(playerId))
|
||||
..addColumns([playerMatchTable.playerId.count()]))
|
||||
.map((row) => row.read(playerMatchTable.playerId.count()))
|
||||
.getSingle();
|
||||
await (selectOnly(playerMatchTable)
|
||||
..where(playerMatchTable.matchId.equals(matchId))
|
||||
..where(playerMatchTable.playerId.equals(playerId))
|
||||
..addColumns([playerMatchTable.playerId.count()]))
|
||||
.map((row) => row.read(playerMatchTable.playerId.count()))
|
||||
.getSingle();
|
||||
return (count ?? 0) > 0;
|
||||
}
|
||||
|
||||
@@ -153,9 +153,9 @@ class PlayerMatchDao extends DatabaseAccessor<AppDatabase>
|
||||
if (playersToRemove.isNotEmpty) {
|
||||
await (delete(playerMatchTable)..where(
|
||||
(pg) =>
|
||||
pg.matchId.equals(matchId) &
|
||||
pg.playerId.isIn(playersToRemove.toList()),
|
||||
))
|
||||
pg.matchId.equals(matchId) &
|
||||
pg.playerId.isIn(playersToRemove.toList()),
|
||||
))
|
||||
.go();
|
||||
}
|
||||
|
||||
@@ -164,15 +164,15 @@ class PlayerMatchDao extends DatabaseAccessor<AppDatabase>
|
||||
final inserts = playersToAdd
|
||||
.map(
|
||||
(id) => PlayerMatchTableCompanion.insert(
|
||||
playerId: id,
|
||||
matchId: matchId,
|
||||
score: 0,
|
||||
),
|
||||
)
|
||||
playerId: id,
|
||||
matchId: matchId,
|
||||
score: 0,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
await Future.wait(
|
||||
inserts.map(
|
||||
(c) => into(
|
||||
(c) => into(
|
||||
playerMatchTable,
|
||||
).insert(c, mode: InsertMode.insertOrIgnore),
|
||||
),
|
||||
@@ -186,16 +186,14 @@ class PlayerMatchDao extends DatabaseAccessor<AppDatabase>
|
||||
required String matchId,
|
||||
required String teamId,
|
||||
}) async {
|
||||
final result = await (select(playerMatchTable)
|
||||
..where(
|
||||
(p) => p.matchId.equals(matchId) & p.teamId.equals(teamId),
|
||||
))
|
||||
.get();
|
||||
final result = await (select(
|
||||
playerMatchTable,
|
||||
)..where((p) => p.matchId.equals(matchId) & p.teamId.equals(teamId))).get();
|
||||
|
||||
if (result.isEmpty) return [];
|
||||
|
||||
final futures = result.map(
|
||||
(row) => db.playerDao.getPlayerById(playerId: row.playerId),
|
||||
(row) => db.playerDao.getPlayerById(playerId: row.playerId),
|
||||
);
|
||||
return Future.wait(futures);
|
||||
}
|
||||
|
||||
@@ -11,4 +11,25 @@ mixin _$PlayerMatchDaoMixin on DatabaseAccessor<AppDatabase> {
|
||||
$TeamTableTable get teamTable => attachedDatabase.teamTable;
|
||||
$PlayerMatchTableTable get playerMatchTable =>
|
||||
attachedDatabase.playerMatchTable;
|
||||
PlayerMatchDaoManager get managers => PlayerMatchDaoManager(this);
|
||||
}
|
||||
|
||||
class PlayerMatchDaoManager {
|
||||
final _$PlayerMatchDaoMixin _db;
|
||||
PlayerMatchDaoManager(this._db);
|
||||
$$PlayerTableTableTableManager get playerTable =>
|
||||
$$PlayerTableTableTableManager(_db.attachedDatabase, _db.playerTable);
|
||||
$$GameTableTableTableManager get gameTable =>
|
||||
$$GameTableTableTableManager(_db.attachedDatabase, _db.gameTable);
|
||||
$$GroupTableTableTableManager get groupTable =>
|
||||
$$GroupTableTableTableManager(_db.attachedDatabase, _db.groupTable);
|
||||
$$MatchTableTableTableManager get matchTable =>
|
||||
$$MatchTableTableTableManager(_db.attachedDatabase, _db.matchTable);
|
||||
$$TeamTableTableTableManager get teamTable =>
|
||||
$$TeamTableTableTableManager(_db.attachedDatabase, _db.teamTable);
|
||||
$$PlayerMatchTableTableTableManager get playerMatchTable =>
|
||||
$$PlayerMatchTableTableTableManager(
|
||||
_db.attachedDatabase,
|
||||
_db.playerMatchTable,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:tallee/data/db/database.dart';
|
||||
import 'package:tallee/data/db/tables/score_table.dart';
|
||||
import 'package:tallee/data/dto/score_entry.dart';
|
||||
import 'package:tallee/data/models/score_entry.dart';
|
||||
|
||||
part 'score_dao.g.dart';
|
||||
|
||||
|
||||
@@ -9,4 +9,20 @@ mixin _$ScoreDaoMixin on DatabaseAccessor<AppDatabase> {
|
||||
$GroupTableTable get groupTable => attachedDatabase.groupTable;
|
||||
$MatchTableTable get matchTable => attachedDatabase.matchTable;
|
||||
$ScoreTableTable get scoreTable => attachedDatabase.scoreTable;
|
||||
ScoreDaoManager get managers => ScoreDaoManager(this);
|
||||
}
|
||||
|
||||
class ScoreDaoManager {
|
||||
final _$ScoreDaoMixin _db;
|
||||
ScoreDaoManager(this._db);
|
||||
$$PlayerTableTableTableManager get playerTable =>
|
||||
$$PlayerTableTableTableManager(_db.attachedDatabase, _db.playerTable);
|
||||
$$GameTableTableTableManager get gameTable =>
|
||||
$$GameTableTableTableManager(_db.attachedDatabase, _db.gameTable);
|
||||
$$GroupTableTableTableManager get groupTable =>
|
||||
$$GroupTableTableTableManager(_db.attachedDatabase, _db.groupTable);
|
||||
$$MatchTableTableTableManager get matchTable =>
|
||||
$$MatchTableTableTableManager(_db.attachedDatabase, _db.matchTable);
|
||||
$$ScoreTableTableTableManager get scoreTable =>
|
||||
$$ScoreTableTableTableManager(_db.attachedDatabase, _db.scoreTable);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:tallee/data/db/database.dart';
|
||||
import 'package:tallee/data/db/tables/team_table.dart';
|
||||
import 'package:tallee/data/dto/player.dart';
|
||||
import 'package:tallee/data/dto/team.dart';
|
||||
import 'package:tallee/data/models/player.dart';
|
||||
import 'package:tallee/data/models/team.dart';
|
||||
|
||||
part 'team_dao.g.dart';
|
||||
|
||||
@@ -144,4 +144,3 @@ class TeamDao extends DatabaseAccessor<AppDatabase> with _$TeamDaoMixin {
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,4 +5,12 @@ part of 'team_dao.dart';
|
||||
// ignore_for_file: type=lint
|
||||
mixin _$TeamDaoMixin on DatabaseAccessor<AppDatabase> {
|
||||
$TeamTableTable get teamTable => attachedDatabase.teamTable;
|
||||
TeamDaoManager get managers => TeamDaoManager(this);
|
||||
}
|
||||
|
||||
class TeamDaoManager {
|
||||
final _$TeamDaoMixin _db;
|
||||
TeamDaoManager(this._db);
|
||||
$$TeamTableTableTableManager get teamTable =>
|
||||
$$TeamTableTableTableManager(_db.attachedDatabase, _db.teamTable);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user