mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-28 04:24:20 +00:00
First joins with CommonTableExpression
This commit is contained in:
1 parent
e1d3c1d7dc
commit
2bb9f5ce0d
8 files changed
+118
-4
No files matched your search
@@ -8,6 +8,12 @@ public struct CommonTableExpression {
|
||||
var key: String
|
||||
var alias: TableAlias
|
||||
var request: Request
|
||||
|
||||
var relationForAll: SQLRelation {
|
||||
SQLRelation(
|
||||
source: .commonTableExpression(alias),
|
||||
selectionPromise: DatabasePromise(value: [AllColumns()]))
|
||||
}
|
||||
}
|
||||
|
||||
extension CommonTableExpression: Refinable {
|
||||
|
||||
@@ -273,6 +273,9 @@ extension QueryInterfaceRequest: TableRequest {
|
||||
// request.filter(keys: ...)
|
||||
// request.orderByPrimaryKey()
|
||||
return tableName
|
||||
case .commonTableExpression:
|
||||
#warning("TODO: is this ok?")
|
||||
fatalError("Request is not based on a database table")
|
||||
case .subquery:
|
||||
// The only current use case for SQLSource.query is the
|
||||
// "trivial count query" (see SQLQuery.countQuery):
|
||||
|
||||
@@ -585,6 +585,34 @@ extension JoinableRequest {
|
||||
public func joining<A: Association>(required association: A) -> Self where A.OriginRowDecoder == RowDecoder {
|
||||
_joining(required: association._sqlAssociation)
|
||||
}
|
||||
|
||||
#warning("TODO: doc")
|
||||
public func including(optional cte: CommonTableExpression, on condition: @escaping (TableAlias, TableAlias) -> SQLExpression) -> Self {
|
||||
_including(optional: association(to: cte, on: condition))
|
||||
}
|
||||
|
||||
#warning("TODO: doc")
|
||||
public func including(required cte: CommonTableExpression, on condition: @escaping (TableAlias, TableAlias) -> SQLExpression) -> Self {
|
||||
_including(required: association(to: cte, on: condition))
|
||||
}
|
||||
|
||||
#warning("TODO: doc")
|
||||
public func joining(optional cte: CommonTableExpression, on condition: @escaping (TableAlias, TableAlias) -> SQLExpression) -> Self {
|
||||
_joining(optional: association(to: cte, on: condition))
|
||||
}
|
||||
|
||||
#warning("TODO: doc")
|
||||
public func joining(required cte: CommonTableExpression, on condition: @escaping (TableAlias, TableAlias) -> SQLExpression) -> Self {
|
||||
_joining(required: association(to: cte, on: condition))
|
||||
}
|
||||
|
||||
private func association(to cte: CommonTableExpression, on condition: @escaping (TableAlias, TableAlias) -> SQLExpression) -> _SQLAssociation {
|
||||
_SQLAssociation(
|
||||
key: .inflected(cte.key),
|
||||
condition: .promise(condition),
|
||||
relation: cte.relationForAll,
|
||||
cardinality: .toOne)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - DerivableRequest
|
||||
|
||||
Reference in new issue
Block a user