support value querying in Objective C

This commit is contained in:
John Rommel Estropia
2016-04-02 21:39:05 +09:00
parent b95aaf151d
commit aa32f5e158
9 changed files with 680 additions and 131 deletions

View File

@@ -188,19 +188,44 @@ public extension CSDataStack {
}
/**
Deletes all `NSManagedObject`s that satisfy the specified `DeleteClause`s. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
Queries aggregate values as specified by the `CSQueryClause`s. Requires at least a `CSSelect` clause, and optional `CSWhere`, `CSOrderBy`, `CSGroupBy`, and `CSTweak` clauses.
- parameter from: a `From` clause indicating the entity type
- parameter deleteClauses: a series of `DeleteClause` instances for the delete request. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: the number of `NSManagedObject`s deleted
A "query" differs from a "fetch" in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.
- parameter from: a `CSFrom` clause indicating the entity type
- parameter selectClause: a `CSSelect` clause indicating the properties to fetch, and with the generic type indicating the return type.
- parameter queryClauses: a series of `CSQueryClause` instances for the query request. Accepts `CSWhere`, `CSOrderBy`, `CSGroupBy`, and `CSTweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `CSSelect` parameter.
*/
@objc
public func deleteAllFrom(from: CSFrom, deleteClauses: [CSDeleteClause]) -> NSNumber? {
@warn_unused_result
public func queryValueFrom(from: CSFrom, selectClause: CSSelect, queryClauses: [CSQueryClause]) -> AnyObject? {
CoreStore.assert(
NSThread.isMainThread(),
"Attempted to delete from a \(typeName(self)) outside the main thread."
"Attempted to query from a \(typeName(self)) outside the main thread."
)
return self.bridgeToSwift.mainContext.deleteAll(from, deleteClauses)
return self.bridgeToSwift.mainContext.queryValue(from, selectClause, queryClauses)
}
/**
Queries a dictionary of attribute values as specified by the `CSQueryClause`s. Requires at least a `CSSelect` clause, and optional `CSWhere`, `CSOrderBy`, `CSGroupBy`, and `CSTweak` clauses.
A "query" differs from a "fetch" in that it only retrieves values already stored in the persistent store. As such, values from unsaved transactions or contexts will not be incorporated in the query result.
- parameter from: a `CSFrom` clause indicating the entity type
- parameter selectClause: a `CSSelect` clause indicating the properties to fetch, and with the generic type indicating the return type.
- parameter queryClauses: a series of `CSQueryClause` instances for the query request. Accepts `CSWhere`, `CSOrderBy`, `CSGroupBy`, and `CSTweak` clauses.
- returns: the result of the the query. The type of the return value is specified by the generic type of the `CSSelect` parameter.
*/
@objc
@warn_unused_result
public func queryAttributesFrom(from: CSFrom, selectClause: CSSelect, queryClauses: [CSQueryClause]) -> [[NSString: AnyObject]]? {
CoreStore.assert(
NSThread.isMainThread(),
"Attempted to query from a \(typeName(self)) outside the main thread."
)
return self.bridgeToSwift.mainContext.queryAttributes(from, selectClause, queryClauses)
}
}