deleted matches get ignored when includeDeleted is false
This commit is contained in:
@@ -255,25 +255,40 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
/* Read */
|
||||
|
||||
/// 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`.
|
||||
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));
|
||||
if (!includeDeleted) {
|
||||
query.where((g) => g.deleted.equals(false));
|
||||
}
|
||||
final result = await query.getSingleOrNull();
|
||||
return result != null;
|
||||
}
|
||||
|
||||
/// Retrieves the number of matches in the database.
|
||||
Future<int> getMatchCount() async {
|
||||
final count =
|
||||
await (selectOnly(matchTable)..addColumns([matchTable.id.count()]))
|
||||
.map((row) => row.read(matchTable.id.count()))
|
||||
.getSingle();
|
||||
/// By default, only returns non-deleted matches.
|
||||
Future<int> getMatchCount({bool includeDeleted = false}) async {
|
||||
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()))
|
||||
.getSingle();
|
||||
return count ?? 0;
|
||||
}
|
||||
|
||||
/// 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);
|
||||
if (!includeDeleted) {
|
||||
query.where((m) => m.deleted.equals(false));
|
||||
}
|
||||
final result = await query.get();
|
||||
|
||||
return Future.wait(
|
||||
@@ -310,8 +325,15 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
}
|
||||
|
||||
/// 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));
|
||||
if (!includeDeleted) {
|
||||
query.where((g) => g.deleted.equals(false));
|
||||
}
|
||||
final result = await query.getSingle();
|
||||
|
||||
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.
|
||||
Future<int> getMatchCountByGame({required String gameId}) async {
|
||||
final count =
|
||||
await (selectOnly(matchTable)
|
||||
..where(matchTable.gameId.equals(gameId))
|
||||
..addColumns([matchTable.id.count()]))
|
||||
.map((row) => row.read(matchTable.id.count()))
|
||||
.getSingle();
|
||||
/// By default, only returns non-deleted matches.
|
||||
Future<int> getMatchCountByGame({
|
||||
required String gameId,
|
||||
bool includeDeleted = false,
|
||||
}) 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()))
|
||||
.getSingle();
|
||||
return count ?? 0;
|
||||
}
|
||||
|
||||
/// Retrieves all matches associated with the given [groupId].
|
||||
/// By default, only returns non-deleted matches.
|
||||
/// 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));
|
||||
if (!includeDeleted) {
|
||||
query.where((m) => m.deleted.equals(false));
|
||||
}
|
||||
final rows = await query.get();
|
||||
|
||||
return Future.wait(
|
||||
|
||||
Reference in New Issue
Block a user