From c6be892cb03d215e6563161a4b1d70f0407eb555 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Sat, 2 Jan 2021 10:00:23 +0900 Subject: [PATCH] added .where(combinedByAnd:) and .where(combinedByOr:) to help compiler with long && and || chains --- Sources/From+Querying.swift | 93 +++++++++++++++++++++++++++++++++++-- 1 file changed, 88 insertions(+), 5 deletions(-) diff --git a/Sources/From+Querying.swift b/Sources/From+Querying.swift index 77eca5a..15dc057 100644 --- a/Sources/From+Querying.swift +++ b/Sources/From+Querying.swift @@ -42,6 +42,28 @@ extension From { return self.fetchChain(appending: clause) } + /** + Creates a `FetchChainBuilder` that `AND`s the specified `Where` clauses. Use this overload if the compiler cannot infer the types when chaining multiple `&&` operators. + + - parameter clauses: the `Where` clauses to create a `FetchChainBuilder` with + - returns: a `FetchChainBuilder` that `AND`s the specified `Where` clauses + */ + public func `where`(combineByAnd clauses: Where...) -> FetchChainBuilder { + + return self.fetchChain(appending: clauses.combinedByAnd()) + } + + /** + Creates a `FetchChainBuilder` that `OR`s the specified `Where` clauses. Use this overload if the compiler cannot infer the types when chaining multiple `||` operators. + + - parameter clauses: the `Where` clauses to create a `FetchChainBuilder` with + - returns: a `FetchChainBuilder` that `OR`s the specified `Where` clauses + */ + public func `where`(combineByOr clauses: Where...) -> FetchChainBuilder { + + return self.fetchChain(appending: clauses.combinedByOr()) + } + /** Creates a `FetchChainBuilder` with a predicate using the specified string format and arguments @@ -295,11 +317,6 @@ extension From where O: CoreStoreObject { return self.fetchChain(appending: clause(O.meta)) } - - public func `where`(combinedByAnd clause: Where, _ others: Where...) -> FetchChainBuilder { - - return self.fetchChain(appending: ([clause] + others).combinedByAnd()) - } /** Creates a `QueryChainBuilder` that starts with a `Select` clause created from the specified key path @@ -544,6 +561,28 @@ extension FetchChainBuilder { return self.fetchChain(appending: clause) } + /** + Creates a `FetchChainBuilder` that `AND`s the specified `Where` clauses. Use this overload if the compiler cannot infer the types when chaining multiple `&&` operators. + + - parameter clauses: the `Where` clauses to create a `FetchChainBuilder` with + - returns: a `FetchChainBuilder` that `AND`s the specified `Where` clauses + */ + public func `where`(combineByAnd clauses: Where...) -> FetchChainBuilder { + + return self.fetchChain(appending: clauses.combinedByAnd()) + } + + /** + Creates a `FetchChainBuilder` that `OR`s the specified `Where` clauses. Use this overload if the compiler cannot infer the types when chaining multiple `||` operators. + + - parameter clauses: the `Where` clauses to create a `FetchChainBuilder` with + - returns: a `FetchChainBuilder` that `OR`s the specified `Where` clauses + */ + public func `where`(combineByOr clauses: Where...) -> FetchChainBuilder { + + return self.fetchChain(appending: clauses.combinedByOr()) + } + /** Adds a `Where` clause to the `FetchChainBuilder` @@ -682,6 +721,28 @@ extension QueryChainBuilder { return self.queryChain(appending: clause) } + /** + Creates a `FetchChainBuilder` that `AND`s the specified `Where` clauses. Use this overload if the compiler cannot infer the types when chaining multiple `&&` operators. + + - parameter clauses: the `Where` clauses to create a `FetchChainBuilder` with + - returns: a `FetchChainBuilder` that `AND`s the specified `Where` clauses + */ + public func `where`(combineByAnd clauses: Where...) -> QueryChainBuilder { + + return self.queryChain(appending: clauses.combinedByAnd()) + } + + /** + Creates a `FetchChainBuilder` that `OR`s the specified `Where` clauses. Use this overload if the compiler cannot infer the types when chaining multiple `||` operators. + + - parameter clauses: the `Where` clauses to create a `FetchChainBuilder` with + - returns: a `FetchChainBuilder` that `OR`s the specified `Where` clauses + */ + public func `where`(combineByOr clauses: Where...) -> QueryChainBuilder { + + return self.queryChain(appending: clauses.combinedByOr()) + } + /** Adds a `Where` clause to the `QueryChainBuilder` @@ -957,6 +1018,28 @@ extension SectionMonitorChainBuilder { return self.sectionMonitorChain(appending: clause) } + /** + Creates a `FetchChainBuilder` that `AND`s the specified `Where` clauses. Use this overload if the compiler cannot infer the types when chaining multiple `&&` operators. + + - parameter clauses: the `Where` clauses to create a `FetchChainBuilder` with + - returns: a `FetchChainBuilder` that `AND`s the specified `Where` clauses + */ + public func `where`(combineByAnd clauses: Where...) -> SectionMonitorChainBuilder { + + return self.sectionMonitorChain(appending: clauses.combinedByAnd()) + } + + /** + Creates a `FetchChainBuilder` that `OR`s the specified `Where` clauses. Use this overload if the compiler cannot infer the types when chaining multiple `||` operators. + + - parameter clauses: the `Where` clauses to create a `FetchChainBuilder` with + - returns: a `FetchChainBuilder` that `OR`s the specified `Where` clauses + */ + public func `where`(combineByOr clauses: Where...) -> SectionMonitorChainBuilder { + + return self.sectionMonitorChain(appending: clauses.combinedByOr()) + } + /** Adds a `Where` clause to the `SectionMonitorChainBuilder`