mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-29 04:24:21 +00:00
Hide _SQLAssociation
This commit is contained in:
1 parent
ed7faa3714
commit
68785d1c2d
13 files changed
+56
-56
No files matched your search
@@ -1,4 +1,4 @@
|
||||
// MARK: - SQLAssociation
|
||||
// MARK: - _SQLAssociation
|
||||
|
||||
/// An SQL association is a non-empty chain of steps which starts at the
|
||||
/// "pivot" and ends on the "destination":
|
||||
@@ -51,7 +51,7 @@
|
||||
/// Origin.including(required: association)
|
||||
///
|
||||
/// :nodoc:
|
||||
public /* TODO: internal */ struct SQLAssociation {
|
||||
public struct _SQLAssociation {
|
||||
// All steps, from pivot to destination. Never empty.
|
||||
private(set) var steps: [SQLAssociationStep]
|
||||
var keyPath: [String] { steps.map(\.keyName) }
|
||||
@@ -91,8 +91,8 @@ public /* TODO: internal */ struct SQLAssociation {
|
||||
}
|
||||
|
||||
/// Returns a new association
|
||||
func through(_ other: SQLAssociation) -> Self {
|
||||
SQLAssociation(steps: other.steps + steps)
|
||||
func through(_ other: _SQLAssociation) -> Self {
|
||||
_SQLAssociation(steps: other.steps + steps)
|
||||
}
|
||||
|
||||
/// Returns the destination of the association, reversing the association
|
||||
@@ -140,12 +140,12 @@ public /* TODO: internal */ struct SQLAssociation {
|
||||
cardinality: .toOne)
|
||||
})
|
||||
.reversed()
|
||||
let reversedAssociation = SQLAssociation(steps: Array(reversedSteps))
|
||||
let reversedAssociation = _SQLAssociation(steps: Array(reversedSteps))
|
||||
return destination.relation.appendingChild(for: reversedAssociation, kind: .oneRequired)
|
||||
}
|
||||
}
|
||||
|
||||
extension SQLAssociation: Refinable { }
|
||||
extension _SQLAssociation: Refinable { }
|
||||
|
||||
struct SQLAssociationStep: Refinable {
|
||||
var key: SQLAssociationKey
|
||||
|
||||
@@ -73,23 +73,23 @@ extension SQLQuery: AggregatingRequest {
|
||||
}
|
||||
|
||||
extension SQLQuery: _JoinableRequest {
|
||||
func _including(all association: SQLAssociation) -> Self {
|
||||
func _including(all association: _SQLAssociation) -> Self {
|
||||
map(\.relation) { $0._including(all: association) }
|
||||
}
|
||||
|
||||
func _including(optional association: SQLAssociation) -> Self {
|
||||
func _including(optional association: _SQLAssociation) -> Self {
|
||||
map(\.relation) { $0._including(optional: association) }
|
||||
}
|
||||
|
||||
func _including(required association: SQLAssociation) -> Self {
|
||||
func _including(required association: _SQLAssociation) -> Self {
|
||||
map(\.relation) { $0._including(required: association) }
|
||||
}
|
||||
|
||||
func _joining(optional association: SQLAssociation) -> Self {
|
||||
func _joining(optional association: _SQLAssociation) -> Self {
|
||||
map(\.relation) { $0._joining(optional: association) }
|
||||
}
|
||||
|
||||
func _joining(required association: SQLAssociation) -> Self {
|
||||
func _joining(required association: _SQLAssociation) -> Self {
|
||||
map(\.relation) { $0._joining(required: association) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ struct SQLRelation {
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate func makeAssociationForKey(_ key: String) -> SQLAssociation {
|
||||
fileprivate func makeAssociationForKey(_ key: String) -> _SQLAssociation {
|
||||
let key = SQLAssociationKey.fixed(key)
|
||||
|
||||
let cardinality: SQLAssociationCardinality
|
||||
@@ -149,7 +149,7 @@ struct SQLRelation {
|
||||
cardinality = .toMany
|
||||
}
|
||||
|
||||
return SQLAssociation(
|
||||
return _SQLAssociation(
|
||||
key: key,
|
||||
condition: condition,
|
||||
relation: relation,
|
||||
@@ -166,8 +166,8 @@ struct SQLRelation {
|
||||
var ordering: SQLRelation.Ordering = SQLRelation.Ordering()
|
||||
var children: OrderedDictionary<String, Child> = [:]
|
||||
|
||||
var prefetchedAssociations: [SQLAssociation] {
|
||||
children.flatMap { key, child -> [SQLAssociation] in
|
||||
var prefetchedAssociations: [_SQLAssociation] {
|
||||
children.flatMap { key, child -> [_SQLAssociation] in
|
||||
switch child.kind {
|
||||
case .allPrefetched:
|
||||
return [child.makeAssociationForKey(key)]
|
||||
@@ -273,7 +273,7 @@ extension SQLRelation {
|
||||
/// HasMany in the above examples, but also for indirect associations such
|
||||
/// as HasManyThrough, which have any number of pivot relations between the
|
||||
/// origin and the destination.
|
||||
func appendingChild(for association: SQLAssociation, kind: SQLRelation.Child.Kind) -> Self {
|
||||
func appendingChild(for association: _SQLAssociation, kind: SQLRelation.Child.Kind) -> Self {
|
||||
// Preserve association cardinality in intermediate steps of
|
||||
// including(all:), and force desired cardinality otherwize
|
||||
let isSingular = (kind == .allNotPrefetched)
|
||||
@@ -315,7 +315,7 @@ extension SQLRelation {
|
||||
//
|
||||
// Let's recurse toward a direct join, by making a new association which
|
||||
// ends on the last pivot, to which we join our destination:
|
||||
var reducedAssociation = SQLAssociation(steps: Array(initialSteps))
|
||||
var reducedAssociation = _SQLAssociation(steps: Array(initialSteps))
|
||||
|
||||
reducedAssociation.destination.relation = reducedAssociation.destination.relation
|
||||
.select([]) // Intermediate steps are not prefetched
|
||||
@@ -366,23 +366,23 @@ extension SQLRelation {
|
||||
}
|
||||
|
||||
extension SQLRelation: _JoinableRequest {
|
||||
func _including(all association: SQLAssociation) -> Self {
|
||||
func _including(all association: _SQLAssociation) -> Self {
|
||||
appendingChild(for: association, kind: .allPrefetched)
|
||||
}
|
||||
|
||||
func _including(optional association: SQLAssociation) -> Self {
|
||||
func _including(optional association: _SQLAssociation) -> Self {
|
||||
appendingChild(for: association, kind: .oneOptional)
|
||||
}
|
||||
|
||||
func _including(required association: SQLAssociation) -> Self {
|
||||
func _including(required association: _SQLAssociation) -> Self {
|
||||
appendingChild(for: association, kind: .oneRequired)
|
||||
}
|
||||
|
||||
func _joining(optional association: SQLAssociation) -> Self {
|
||||
func _joining(optional association: _SQLAssociation) -> Self {
|
||||
appendingChild(for: association.map(\.destination.relation, { $0.select([]) }), kind: .oneOptional)
|
||||
}
|
||||
|
||||
func _joining(required association: SQLAssociation) -> Self {
|
||||
func _joining(required association: _SQLAssociation) -> Self {
|
||||
appendingChild(for: association.map(\.destination.relation, { $0.select([]) }), kind: .oneRequired)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user