From a88f20fb507e26ef98597d0e0d24bf3df39ad52e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 28 Apr 2019 19:31:20 +0200 Subject: [PATCH] Introduce including(all:) --- GRDB/QueryInterface/Association/Association.swift | 7 +++++++ .../QueryInterfaceRequest+Association.swift | 14 ++++++++++++++ GRDB/QueryInterface/QueryInterfaceRequest.swift | 1 + 3 files changed, 22 insertions(+) diff --git a/GRDB/QueryInterface/Association/Association.swift b/GRDB/QueryInterface/Association/Association.swift index 93e4d1787..0d963febe 100644 --- a/GRDB/QueryInterface/Association/Association.swift +++ b/GRDB/QueryInterface/Association/Association.swift @@ -242,6 +242,13 @@ extension Association { } extension Association { + /// Creates an association that prefetches another one. + public func including(all association: A) -> Self where A.OriginRowDecoder == RowDecoder { + return mapRelation { + _ in fatalError("TODO") + } + } + /// Creates an association that includes another one. The columns of the /// associated record are selected. The returned association does not /// require that the associated database table contains a matching row. diff --git a/GRDB/QueryInterface/QueryInterfaceRequest+Association.swift b/GRDB/QueryInterface/QueryInterfaceRequest+Association.swift index 53beba3c1..00a8bd39a 100644 --- a/GRDB/QueryInterface/QueryInterfaceRequest+Association.swift +++ b/GRDB/QueryInterface/QueryInterfaceRequest+Association.swift @@ -1,6 +1,15 @@ extension QueryInterfaceRequest where RowDecoder: TableRecord { // MARK: - Associations + /// Creates a request that prefetches an association. + public func including(all association: A) -> QueryInterfaceRequest where A.OriginRowDecoder == RowDecoder { + return mapQuery { + $0.mapRelation { + _ in fatalError("TODO") + } + } + } + /// Creates a request that includes an association. The columns of the /// associated record are selected. The returned association does not /// require that the associated database table contains a matching row. @@ -119,6 +128,11 @@ extension TableRecord { // MARK: - Associations + /// Creates a request that prefetches an association. + public static func including(all association: A) -> QueryInterfaceRequest where A.OriginRowDecoder == Self { + return all().including(all: association) + } + /// Creates a request that includes an association. The columns of the /// associated record are selected. The returned association does not /// require that the associated database table contains a matching row. diff --git a/GRDB/QueryInterface/QueryInterfaceRequest.swift b/GRDB/QueryInterface/QueryInterfaceRequest.swift index 886b57193..18387724c 100644 --- a/GRDB/QueryInterface/QueryInterfaceRequest.swift +++ b/GRDB/QueryInterface/QueryInterfaceRequest.swift @@ -66,6 +66,7 @@ extension QueryInterfaceRequest : FetchRequest { /// - parameter db: A database connection. /// :nodoc: public func databaseRegion(_ db: Database) throws -> DatabaseRegion { + // TODO: include prefetched regions return try SQLSelectQueryGenerator(query).databaseRegion(db) } }