Skip to content

Commit fd5d55a

Browse files
committed
Add filter by colors method to GRDBCard requests
1 parent 66c27db commit fd5d55a

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Foundation
2+
import GRDB
3+
4+
extension DerivableRequest<GRDBCard> {
5+
func filter(colors: [ScryfallColor]) -> Self {
6+
self.joining(
7+
required: GRDBCard.colors.filter { colors.contains($0.color) }
8+
)
9+
.distinct()
10+
}
11+
}

CubeSightTests/CardColorTests.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ struct CardColorTests {
2525
let db = try await makeAppDatabase()
2626

2727
let count = try await db.reader.read { db in
28-
try GRDBCard.joining(
29-
required: GRDBCard.colors.filter { tc.colors.contains($0.color) }
30-
)
31-
.distinct()
32-
.fetchCount(db)
28+
return try GRDBCard.all().filter(colors: tc.colors).fetchCount(db)
3329
}
3430
#expect(count == tc.expectedCount)
3531
}

0 commit comments

Comments
 (0)