From e45d67252c9001818a35ea57ee5f88b1ef6ca454 Mon Sep 17 00:00:00 2001 From: John Rommel Estropia Date: Wed, 20 Sep 2017 00:24:03 +0900 Subject: [PATCH] CoreStore querying utilities --- Sources/CoreStore+Querying.swift | 42 ++++++++++++++++++++++++++++++++ Sources/CoreStoreBridge.h | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/Sources/CoreStore+Querying.swift b/Sources/CoreStore+Querying.swift index 3d403ef..9e275bb 100644 --- a/Sources/CoreStore+Querying.swift +++ b/Sources/CoreStore+Querying.swift @@ -99,6 +99,12 @@ public extension CoreStore { return self.defaultStack.fetchOne(from, fetchClauses) } + // TODO: docs + public static func fetchOne(_ clauseChain: B) -> B.ObjectType? { + + return self.defaultStack.fetchOne(clauseChain) + } + /** Using the `defaultStack`, fetches all `DynamicObject` instances that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -123,6 +129,12 @@ public extension CoreStore { return self.defaultStack.fetchAll(from, fetchClauses) } + // TODO: docs + public static func fetchAll(_ clauseChain: B) -> [B.ObjectType]? { + + return self.defaultStack.fetchAll(clauseChain) + } + /** Using the `defaultStack`, fetches the number of `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -147,6 +159,12 @@ public extension CoreStore { return self.defaultStack.fetchCount(from, fetchClauses) } + // TODO: docs + public static func fetchCount(_ clauseChain: B) -> Int? { + + return self.defaultStack.fetchCount(clauseChain) + } + /** Using the `defaultStack`, fetches the `NSManagedObjectID` for the first `DynamicObject` that satisfies the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -171,6 +189,12 @@ public extension CoreStore { return self.defaultStack.fetchObjectID(from, fetchClauses) } + // TODO: docs + public static func fetchObjectID(_ clauseChain: B) -> NSManagedObjectID? { + + return self.defaultStack.fetchObjectID(clauseChain) + } + /** Using the `defaultStack`, fetches the `NSManagedObjectID` for all `DynamicObject`s that satisfy the specified `FetchClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses. @@ -195,6 +219,12 @@ public extension CoreStore { return self.defaultStack.fetchObjectIDs(from, fetchClauses) } + // TODO: docs + public static func fetchObjectIDs(_ clauseChain: B) -> [NSManagedObjectID]? { + + return self.defaultStack.fetchObjectIDs(clauseChain) + } + /** Using the `defaultStack`, queries aggregate values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. @@ -225,6 +255,12 @@ public extension CoreStore { return self.defaultStack.queryValue(from, selectClause, queryClauses) } + // TODO: docs + public static func queryValue(_ clauseChain: B) -> B.ResultType? where B.ResultType: QueryableAttributeType { + + return self.defaultStack.queryValue(clauseChain) + } + /** Using the `defaultStack`, queries a dictionary of attribtue values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses. @@ -254,4 +290,10 @@ public extension CoreStore { return self.defaultStack.queryAttributes(from, selectClause, queryClauses) } + + // TODO: docs + public static func queryAttributes(_ clauseChain: B) -> [[String: Any]]? where B.ResultType == NSDictionary { + + return self.defaultStack.queryAttributes(clauseChain) + } } diff --git a/Sources/CoreStoreBridge.h b/Sources/CoreStoreBridge.h index 43dfc6d..5762ce2 100644 --- a/Sources/CoreStoreBridge.h +++ b/Sources/CoreStoreBridge.h @@ -477,7 +477,7 @@ CSSelect *_Nonnull CSSelectData(CSSelectTerm *_Nonnull selectTerm) CORESTORE_RET a CSSelect clause for querying an NSManagedObjectID value */ CORESTORE_EXTERN -CSSelect *_Nonnull CSSelectObjectID() CORESTORE_RETURNS_RETAINED; +CSSelect *_Nonnull CSSelectObjectID(void) CORESTORE_RETURNS_RETAINED; #pragma mark CSTweak