selectOnly() clears the isDistinct flag

This commit is contained in:
Gwendal Roué committed 2021-03-08 21:36:09 +01:00
1 parent 4521e6b37d
commit ed3d1e1ac4
2 files changed
+12 -10

No files matched your search

@@ -524,8 +524,7 @@ private struct SQLQualifiedRelation {
/// The selection from source, not including selection of joined relations
private var sourceSelectionPromise: DatabasePromise<[SQLSelection]>
#warning("TODO: decide if selectOnly() should reset this flag")
let isDistinct: Bool
var isDistinct: Bool
/// The full selection, including selection of joined relations
var selectionPromise: DatabasePromise<[SQLSelection]> {
@@ -651,14 +650,20 @@ private struct SQLQualifiedRelation {
return (adapter: adapter, endIndex: endIndex)
}
/// Removes all selections from joins
/// Sets the selection, removes all selections from joins, and clears the
/// `isDistinct` flag.
func selectOnly(_ selection: [SQLSelection]) -> Self {
let sourceSelectionPromise = DatabasePromise(value: selection.map {
$0.qualified(with: source.alias)
})
return self
.with(\.sourceSelectionPromise, sourceSelectionPromise)
.map(\.joins, { $0.mapValues { $0.selectOnly([]) } })
.with(\.isDistinct, false)
.map(\.joins, { joins in
joins.mapValues { join in
join.map(\.relation) { $0.selectOnly([]) }
}
})
}
}
@@ -720,11 +725,6 @@ private struct SQLQualifiedJoin: Refinable {
try sql(context, leftAlias: leftAlias, allowingInnerJoin: true)
}
/// Removes all selections from joins
func selectOnly(_ selection: [SQLSelection]) -> SQLQualifiedJoin {
map(\.relation) { $0.selectOnly(selection) }
}
private func sql(
_ context: SQLGenerationContext,
leftAlias: TableAlias,