-
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #621 from vapor/querybuilder-copy
Add support for copying query builders.
- Loading branch information
Showing
1 changed file
with
16 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
extension QueryBuilder { | ||
// MARK: Copy | ||
|
||
/// Creates a copy of the current query builder. Useful for constructing two similar, but not identical, queries. | ||
/// | ||
/// Example: two queries sorted by different criteria. | ||
/// | ||
/// let baseQuery = try User.query(on: conn).filter(\.name == "foo") | ||
/// let sortedByID = baseQuery.copy().sort(\.id, .ascending) | ||
/// let sortedByName = baseQuery.copy().sort(\.name, .ascending) | ||
/// | ||
/// - returns: A copy of the current query builder that can be manipulated independently of the original. | ||
public func copy() -> Self { | ||
return .init(query: self.query, on: self.connection, resultTransformer: self.resultTransformer) | ||
} | ||
} |