mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
selectOnly() clears the isDistinct flag
This commit is contained in:
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,
|
||||
|
||||
Reference in new issue
Block a user