First joins with CommonTableExpression

This commit is contained in:
Gwendal Roué committed 2020-11-29 19:05:12 +01:00
1 parent e1d3c1d7dc
commit 2bb9f5ce0d
8 files changed
+118 -4

No files matched your search

@@ -144,6 +144,11 @@ private func prefetch(_ db: Database, associations: [_SQLAssociation], in rows:
// CAUTION: Keep this code in sync with prefetchedRegion(_:_:)
for association in associations {
switch association.pivot.condition {
case .promise:
// Likely a GRDB bug: such condition only exist for CTEs, which
// are not prefetched.
fatalError("Not implemented: prefetch association without any foreign key")
case let .foreignKey(request: foreignKeyRequest, originIsLeft: originIsLeft):
// Annotate prefetched rows with pivot columns, so that we can
// group them.
@@ -204,6 +209,11 @@ func prefetchedRegion(_ db: Database, associations: [_SQLAssociation]) throws ->
try associations.reduce(into: DatabaseRegion()) { (region, association) in
// CAUTION: Keep this code in sync with prefetch(_:associations:in:)
switch association.pivot.condition {
case .promise:
// Likely a GRDB bug: such condition only exist for CTEs, which
// are not prefetched.
fatalError("Not implemented: prefetch association without any foreign key")
case let .foreignKey(request: foreignKeyRequest, originIsLeft: originIsLeft):
// Filter the pivot on a `NullRow` in order to make sure all join
// condition columns are made visible to SQLite, and present in the