WIP: Implementierung von deleted Attribut #204
@@ -255,25 +255,40 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
|||||||
/* Read */
|
/* Read */
|
||||||
|
|
||||||
/// Checks if a match with the given [matchId] exists in the database.
|
/// Checks if a match with the given [matchId] exists in the database.
|
||||||
|
/// By default, only returns non-deleted matches.
|
||||||
/// Returns `true` if the match exists, otherwise `false`.
|
/// Returns `true` if the match exists, otherwise `false`.
|
||||||
Future<bool> matchExists({required String matchId}) async {
|
Future<bool> matchExists({
|
||||||
|
required String matchId,
|
||||||
|
bool includeDeleted = false,
|
||||||
|
}) async {
|
||||||
final query = select(matchTable)..where((g) => g.id.equals(matchId));
|
final query = select(matchTable)..where((g) => g.id.equals(matchId));
|
||||||
|
if (!includeDeleted) {
|
||||||
|
query.where((g) => g.deleted.equals(false));
|
||||||
|
}
|
||||||
final result = await query.getSingleOrNull();
|
final result = await query.getSingleOrNull();
|
||||||
return result != null;
|
return result != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves the number of matches in the database.
|
/// Retrieves the number of matches in the database.
|
||||||
Future<int> getMatchCount() async {
|
/// By default, only returns non-deleted matches.
|
||||||
final count =
|
Future<int> getMatchCount({bool includeDeleted = false}) async {
|
||||||
await (selectOnly(matchTable)..addColumns([matchTable.id.count()]))
|
final query = selectOnly(matchTable)..addColumns([matchTable.id.count()]);
|
||||||
|
if (!includeDeleted) {
|
||||||
|
query.where(matchTable.deleted.equals(false));
|
||||||
|
}
|
||||||
|
final count = await query
|
||||||
.map((row) => row.read(matchTable.id.count()))
|
.map((row) => row.read(matchTable.id.count()))
|
||||||
.getSingle();
|
.getSingle();
|
||||||
return count ?? 0;
|
return count ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves all matches from the database.
|
/// Retrieves all matches from the database.
|
||||||
Future<List<Match>> getAllMatches() async {
|
/// By default, only returns non-deleted matches.
|
||||||
|
Future<List<Match>> getAllMatches({bool includeDeleted = false}) async {
|
||||||
final query = select(matchTable);
|
final query = select(matchTable);
|
||||||
|
if (!includeDeleted) {
|
||||||
|
query.where((m) => m.deleted.equals(false));
|
||||||
|
}
|
||||||
final result = await query.get();
|
final result = await query.get();
|
||||||
|
|
||||||
return Future.wait(
|
return Future.wait(
|
||||||
@@ -310,8 +325,15 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves a [Match] by its [matchId].
|
/// Retrieves a [Match] by its [matchId].
|
||||||
Future<Match> getMatchById({required String matchId}) async {
|
/// By default, only returns non-deleted matches.
|
||||||
|
Future<Match> getMatchById({
|
||||||
|
required String matchId,
|
||||||
|
bool includeDeleted = false,
|
||||||
|
}) async {
|
||||||
final query = select(matchTable)..where((g) => g.id.equals(matchId));
|
final query = select(matchTable)..where((g) => g.id.equals(matchId));
|
||||||
|
if (!includeDeleted) {
|
||||||
|
query.where((g) => g.deleted.equals(false));
|
||||||
|
}
|
||||||
final result = await query.getSingle();
|
final result = await query.getSingle();
|
||||||
|
|
||||||
final game = await db.gameDao.getGameById(gameId: result.gameId);
|
final game = await db.gameDao.getGameById(gameId: result.gameId);
|
||||||
@@ -342,20 +364,34 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves the number of matches associated with a specific game.
|
/// Retrieves the number of matches associated with a specific game.
|
||||||
Future<int> getMatchCountByGame({required String gameId}) async {
|
/// By default, only returns non-deleted matches.
|
||||||
final count =
|
Future<int> getMatchCountByGame({
|
||||||
await (selectOnly(matchTable)
|
required String gameId,
|
||||||
..where(matchTable.gameId.equals(gameId))
|
bool includeDeleted = false,
|
||||||
..addColumns([matchTable.id.count()]))
|
}) async {
|
||||||
|
final query = selectOnly(matchTable)
|
||||||
|
..where(matchTable.gameId.equals(gameId));
|
||||||
|
if (!includeDeleted) {
|
||||||
|
query.where(matchTable.deleted.equals(false));
|
||||||
|
}
|
||||||
|
query.addColumns([matchTable.id.count()]);
|
||||||
|
final count = await query
|
||||||
.map((row) => row.read(matchTable.id.count()))
|
.map((row) => row.read(matchTable.id.count()))
|
||||||
.getSingle();
|
.getSingle();
|
||||||
return count ?? 0;
|
return count ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves all matches associated with the given [groupId].
|
/// Retrieves all matches associated with the given [groupId].
|
||||||
|
/// By default, only returns non-deleted matches.
|
||||||
/// Queries the database directly, filtering by [groupId].
|
/// Queries the database directly, filtering by [groupId].
|
||||||
Future<List<Match>> getMatchesByGroup({required String groupId}) async {
|
Future<List<Match>> getMatchesByGroup({
|
||||||
|
required String groupId,
|
||||||
|
bool includeDeleted = false,
|
||||||
|
}) async {
|
||||||
final query = select(matchTable)..where((m) => m.groupId.equals(groupId));
|
final query = select(matchTable)..where((m) => m.groupId.equals(groupId));
|
||||||
|
if (!includeDeleted) {
|
||||||
|
query.where((m) => m.deleted.equals(false));
|
||||||
|
}
|
||||||
final rows = await query.get();
|
final rows = await query.get();
|
||||||
|
|
||||||
return Future.wait(
|
return Future.wait(
|
||||||
|
|||||||
Reference in New Issue
Block a user