mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
More cte association api experiments
This commit is contained in:
1 parent
f31dd0033c
commit
c16da693df
3 files changed
+28
-25
No files matched your search
@@ -2,7 +2,9 @@
|
||||
public struct CommonTableExpression {
|
||||
var tableName: String
|
||||
var request: _FetchRequest
|
||||
|
||||
}
|
||||
|
||||
extension CommonTableExpression {
|
||||
var relationForAll: SQLRelation {
|
||||
SQLRelation(
|
||||
source: .table(tableName: tableName, alias: nil),
|
||||
@@ -13,6 +15,19 @@ public struct CommonTableExpression {
|
||||
public func all() -> QueryInterfaceRequest<Void> {
|
||||
QueryInterfaceRequest(relation: relationForAll)
|
||||
}
|
||||
}
|
||||
|
||||
extension CommonTableExpression {
|
||||
#warning("TODO: Do we need to be able to provide a foreign key? A USING clause?")
|
||||
#warning("TODO: doc")
|
||||
public func association<T>(from: T.Type = T.self, on condition: @escaping (TableAlias, TableAlias) -> SQLExpressible)
|
||||
-> JoinAssociation<T, Void>
|
||||
{
|
||||
JoinAssociation(
|
||||
key: .inflected(tableName),
|
||||
condition: .promise(condition),
|
||||
relation: relationForAll)
|
||||
}
|
||||
|
||||
#warning("TODO: Do we need to be able to provide a foreign key? A USING clause?")
|
||||
#warning("TODO: doc")
|
||||
@@ -32,7 +47,7 @@ public struct CommonTableExpression {
|
||||
public func association<Destination>(
|
||||
to destination: Destination.Type,
|
||||
on condition: @escaping (TableAlias, TableAlias) -> SQLExpressible)
|
||||
-> JoinAssociation<Void, Void>
|
||||
-> JoinAssociation<Void, Destination>
|
||||
where Destination: TableRecord
|
||||
{
|
||||
JoinAssociation(
|
||||
|
||||
@@ -357,19 +357,6 @@ extension TableRecord {
|
||||
return association
|
||||
}
|
||||
}
|
||||
|
||||
#warning("TODO: Do we need to be able to provide a foreign key? A USING clause?")
|
||||
#warning("TODO: doc")
|
||||
public static func association(
|
||||
to cte: CommonTableExpression,
|
||||
on condition: @escaping (TableAlias, TableAlias) -> SQLExpressible)
|
||||
-> JoinAssociation<Self, Void>
|
||||
{
|
||||
JoinAssociation(
|
||||
key: .inflected(cte.tableName),
|
||||
condition: .promise(condition),
|
||||
relation: cte.relationForAll)
|
||||
}
|
||||
}
|
||||
|
||||
/// A ForeignKey helps building associations when GRDB can't infer a foreign
|
||||
|
||||
Reference in new issue
Block a user