Skip to content

Commit

Permalink
Fix query to properly count 'outOf' (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrandonw authored Apr 8, 2021
1 parent 30dda41 commit f770021
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Sources/DatabaseLive/DatabaseLive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ extension DatabaseClient {
WHERE "leaderboardScores"."dailyChallengeId" = \(bind: request.dailyChallengeId)
),
"filteredDailyChallengeScoresCount" AS (
SELECT count(DISTINCT "score") AS "outOf"
SELECT count("playerId") AS "outOf"
FROM "filteredDailyChallengeScores"
),
"playerDailyChallengeResult" AS (
Expand Down Expand Up @@ -238,7 +238,7 @@ extension DatabaseClient {
AND "dailyChallenges"."language" = \(bind: request.language)
),
"rankedChallengeResultsCount" AS (
SELECT count(DISTINCT "score") AS "outOf"
SELECT count("playerId") AS "outOf"
FROM "rankedChallengeResults"
)
SELECT
Expand Down
8 changes: 4 additions & 4 deletions Tests/DatabaseLiveTests/DatabaseLiveTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,10 @@ class DatabaseLiveTests: DatabaseTestCase {
XCTAssertEqual(
results,
[
.init(outOf: 3, rank: 3, score: 1_000),
.init(outOf: 3, rank: 2, score: 2_000),
.init(outOf: 3, rank: 1, score: 3_000),
.init(outOf: 3, rank: 2, score: 2_000),
.init(outOf: 4, rank: 3, score: 1_000),
.init(outOf: 4, rank: 2, score: 2_000),
.init(outOf: 4, rank: 1, score: 3_000),
.init(outOf: 4, rank: 2, score: 2_000),
]
)
}
Expand Down

0 comments on commit f770021

Please sign in to comment.