complete query utilities

This commit is contained in:
John Rommel Estropia
2017-08-08 07:36:52 +09:00
parent fe69e7c6c4
commit 4a5bc6450b
13 changed files with 325 additions and 230 deletions

View File

@@ -32,12 +32,7 @@ import CoreData
/**
The `GroupBy` clause specifies that the result of a query be grouped accoording to the specified key path.
*/
public struct GroupBy: QueryClause, Hashable {
/**
The list of key path strings to group results with
*/
public let keyPaths: [KeyPathString]
public struct GroupBy<D: DynamicObject>: GroupByClause, QueryClause, Hashable {
/**
Initializes a `GroupBy` clause with an empty list of key path strings
@@ -69,6 +64,13 @@ public struct GroupBy: QueryClause, Hashable {
}
// MARK: WhereClause
public typealias ObjectType = D
public let keyPaths: [KeyPathString]
// MARK: QueryClause
public func applyToFetchRequest<ResultType>(_ fetchRequest: NSFetchRequest<ResultType>) {
@@ -100,3 +102,22 @@ public struct GroupBy: QueryClause, Hashable {
return (self.keyPaths as NSArray).hashValue
}
}
// MARK: - GroupByClause
/**
Abstracts the `GroupBy` clause for protocol utilities.
*/
public protocol GroupByClause {
/**
The `DynamicObject` type associated with the clause
*/
associatedtype ObjectType: DynamicObject
/**
The list of key path strings to group results with
*/
var keyPaths: [KeyPathString] { get }
}