mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
Replace JoinQuery initializer with QueryInterfaceRequest.asJoinQuery()
This commit is contained in:
1 parent
9d391badc0
commit
5f037c7e4e
5 files changed
+29
-19
No files matched your search
@@ -187,6 +187,6 @@ extension TableRecord {
|
||||
return BelongsToAssociation(
|
||||
key: key ?? Destination.databaseTableName,
|
||||
joinCondition: joinCondition,
|
||||
query: JoinQuery(Destination.all().query))
|
||||
query: Destination.all().asJoinQuery())
|
||||
}
|
||||
}
|
||||
@@ -276,6 +276,6 @@ extension TableRecord {
|
||||
return HasManyAssociation(
|
||||
key: key ?? Destination.databaseTableName,
|
||||
joinCondition: joinCondition,
|
||||
query: JoinQuery(Destination.all().query))
|
||||
query: Destination.all().asJoinQuery())
|
||||
}
|
||||
}
|
||||
@@ -189,6 +189,6 @@ extension TableRecord {
|
||||
return HasOneAssociation(
|
||||
key: key ?? Destination.databaseTableName,
|
||||
joinCondition: joinCondition,
|
||||
query: JoinQuery(Destination.all().query))
|
||||
query: Destination.all().asJoinQuery())
|
||||
}
|
||||
}
|
||||
@@ -13,22 +13,6 @@ public /* TODO: make internal when possible */ struct JoinQuery {
|
||||
}
|
||||
}
|
||||
|
||||
extension JoinQuery {
|
||||
init(_ query: QueryInterfaceQuery) {
|
||||
GRDBPrecondition(!query.isDistinct, "Not implemented: join distinct queries")
|
||||
GRDBPrecondition(query.groupPromise == nil, "Can't join aggregated queries")
|
||||
GRDBPrecondition(query.havingExpression == nil, "Can't join aggregated queries")
|
||||
GRDBPrecondition(query.limit == nil, "Can't join limited queries")
|
||||
|
||||
self.init(
|
||||
source: query.source,
|
||||
selection: query.selection,
|
||||
filterPromise: query.filterPromise,
|
||||
ordering: query.ordering,
|
||||
joins: query.joins)
|
||||
}
|
||||
}
|
||||
|
||||
extension JoinQuery {
|
||||
func select(_ selection: [SQLSelectable]) -> JoinQuery {
|
||||
var query = self
|
||||
|
||||
@@ -226,6 +226,32 @@ extension QueryInterfaceRequest : DerivableRequest, AggregatingRequest {
|
||||
}
|
||||
}
|
||||
|
||||
extension QueryInterfaceRequest {
|
||||
/// Turns a request into a JoinQuery.
|
||||
///
|
||||
/// This method helps initializing associations:
|
||||
///
|
||||
/// struct Book: TableRecord {
|
||||
/// // invokes Author.all().asJoinQuery()
|
||||
/// static let author = belongsTo(Author.self)
|
||||
/// }
|
||||
func asJoinQuery() -> JoinQuery {
|
||||
let query = self.query
|
||||
|
||||
GRDBPrecondition(!query.isDistinct, "Not implemented: join distinct queries")
|
||||
GRDBPrecondition(query.groupPromise == nil, "Can't join aggregated queries")
|
||||
GRDBPrecondition(query.havingExpression == nil, "Can't join aggregated queries")
|
||||
GRDBPrecondition(query.limit == nil, "Can't join limited queries")
|
||||
|
||||
return JoinQuery(
|
||||
source: query.source,
|
||||
selection: query.selection,
|
||||
filterPromise: query.filterPromise,
|
||||
ordering: query.ordering,
|
||||
joins: query.joins)
|
||||
}
|
||||
}
|
||||
|
||||
/// Conditional conformance to TableRequest when RowDecoder conforms
|
||||
/// to TableRecord:
|
||||
///
|
||||
|
||||
Reference in new issue
Block a user