mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-22 17:39:52 +01:00
WIP: compilable again now
This commit is contained in:
@@ -287,7 +287,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||
*/
|
||||
public func queryValue<T: NSManagedObject, U: CoreStoreQueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
|
||||
public func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
@@ -306,7 +306,7 @@ extension BaseDataTransaction: FetchableSource, QueryableSource {
|
||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||
*/
|
||||
public func queryValue<T: NSManagedObject, U: CoreStoreQueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
|
||||
public func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
|
||||
|
||||
CoreStore.assert(
|
||||
self.isRunningInAllowedQueue(),
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import CoreGraphics
|
||||
import CoreData
|
||||
|
||||
|
||||
@@ -32,34 +33,31 @@ import CoreData
|
||||
/**
|
||||
The `SelectResultType` protocol is implemented by return types supported by the `Select` clause.
|
||||
*/
|
||||
public protocol SelectResultType: CoreStoreQueryableAttributeType {
|
||||
public protocol SelectResultType {}
|
||||
|
||||
|
||||
// MARK: - SelectValueResultType
|
||||
|
||||
/**
|
||||
The `SelectValueResultType` protocol is implemented by return types supported by the `queryValue(...)` methods.
|
||||
*/
|
||||
public protocol SelectValueResultType: SelectResultType {
|
||||
|
||||
static var cs_rawAttributeType: NSAttributeType { get }
|
||||
|
||||
static func cs_fromQueryResultNativeType(_ value: Any) -> Self?
|
||||
}
|
||||
|
||||
|
||||
//// MARK: - SelectValueResultType
|
||||
//
|
||||
///**
|
||||
// The `SelectValueResultType` protocol is implemented by return types supported by the `queryValue(...)` methods.
|
||||
// */
|
||||
//public protocol SelectValueResultType: SelectResultType {
|
||||
//
|
||||
// static var attributeType: NSAttributeType { get }
|
||||
//
|
||||
// static func fromResultObject(_ result: Any) -> Self?
|
||||
//}
|
||||
// MARK: - SelectAttributesResultType
|
||||
|
||||
|
||||
//// MARK: - SelectAttributesResultType
|
||||
//
|
||||
///**
|
||||
// The `SelectValueResultType` protocol is implemented by return types supported by the `queryAttributes(...)` methods.
|
||||
// */
|
||||
//public protocol SelectAttributesResultType: SelectResultType {
|
||||
//
|
||||
// static func fromResultObjects(_ result: [Any]) -> [[String: Any]]
|
||||
//}
|
||||
/**
|
||||
The `SelectAttributesResultType` protocol is implemented by return types supported by the `queryAttributes(...)` methods.
|
||||
*/
|
||||
public protocol SelectAttributesResultType: SelectResultType {
|
||||
|
||||
static func cs_fromQueryResultsNativeType(_ result: [Any]) -> [[String: Any]]
|
||||
}
|
||||
|
||||
|
||||
// MARK: - SelectTerm
|
||||
@@ -338,7 +336,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
|
||||
|
||||
- parameter sortDescriptors: a series of `NSSortDescriptor`s
|
||||
*/
|
||||
public struct Select<T: CoreStoreQueryableAttributeType>: Hashable {
|
||||
public struct Select<T: SelectResultType>: Hashable {
|
||||
|
||||
/**
|
||||
The `SelectResultType` type for the query's return value
|
||||
@@ -369,7 +367,7 @@ public struct Select<T: CoreStoreQueryableAttributeType>: Hashable {
|
||||
|
||||
// MARK: Equatable
|
||||
|
||||
public static func == <T: CoreStoreQueryableAttributeType, U: CoreStoreQueryableAttributeType>(lhs: Select<T>, rhs: Select<U>) -> Bool {
|
||||
public static func == <T: SelectResultType, U: SelectResultType>(lhs: Select<T>, rhs: Select<U>) -> Bool {
|
||||
|
||||
return lhs.selectTerms == rhs.selectTerms
|
||||
}
|
||||
@@ -397,340 +395,204 @@ public extension Select where T: NSManagedObjectID {
|
||||
}
|
||||
|
||||
|
||||
//// MARK: - Bool: SelectValueResultType
|
||||
//
|
||||
//extension Bool: SelectValueResultType {
|
||||
//
|
||||
// public static var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .booleanAttributeType
|
||||
// }
|
||||
//
|
||||
// public static func fromResultObject(_ result: Any) -> Bool? {
|
||||
// switch result {
|
||||
//
|
||||
// case let decimal as NSDecimalNumber:
|
||||
// // iOS: NSDecimalNumber(string: "0.5").boolValue // true
|
||||
// // OSX: NSDecimalNumber(string: "0.5").boolValue // false
|
||||
// return NSNumber(value: decimal.doubleValue).boolValue
|
||||
//
|
||||
// case let number as NSNumber:
|
||||
// return number.boolValue
|
||||
//
|
||||
// default:
|
||||
// return nil
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - Int8: SelectValueResultType
|
||||
//
|
||||
//extension Int8: SelectValueResultType {
|
||||
//
|
||||
// public static var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .integer64AttributeType
|
||||
// }
|
||||
//
|
||||
// public static func fromResultObject(_ result: Any) -> Int8? {
|
||||
//
|
||||
// guard let value = (result as? NSNumber)?.int64Value else {
|
||||
//
|
||||
// return nil
|
||||
// }
|
||||
// return numericCast(value) as Int8
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - Int16: SelectValueResultType
|
||||
//
|
||||
//extension Int16: SelectValueResultType {
|
||||
//
|
||||
// public static var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .integer64AttributeType
|
||||
// }
|
||||
//
|
||||
// public static func fromResultObject(_ result: Any) -> Int16? {
|
||||
//
|
||||
// guard let value = (result as? NSNumber)?.int64Value else {
|
||||
//
|
||||
// return nil
|
||||
// }
|
||||
// return numericCast(value) as Int16
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - Int32: SelectValueResultType
|
||||
//
|
||||
//extension Int32: SelectValueResultType {
|
||||
//
|
||||
// public static var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .integer64AttributeType
|
||||
// }
|
||||
//
|
||||
// public static func fromResultObject(_ result: Any) -> Int32? {
|
||||
//
|
||||
// guard let value = (result as? NSNumber)?.int64Value else {
|
||||
//
|
||||
// return nil
|
||||
// }
|
||||
// return numericCast(value) as Int32
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - Int64: SelectValueResultType
|
||||
//
|
||||
//extension Int64: SelectValueResultType {
|
||||
//
|
||||
// public static var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .integer64AttributeType
|
||||
// }
|
||||
//
|
||||
// public static func fromResultObject(_ result: Any) -> Int64? {
|
||||
//
|
||||
// return (result as? NSNumber)?.int64Value
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - Int: SelectValueResultType
|
||||
//
|
||||
//extension Int: SelectValueResultType {
|
||||
//
|
||||
// public static var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .integer64AttributeType
|
||||
// }
|
||||
//
|
||||
// public static func fromResultObject(_ result: Any) -> Int? {
|
||||
//
|
||||
// guard let value = (result as? NSNumber)?.int64Value else {
|
||||
//
|
||||
// return nil
|
||||
// }
|
||||
// return numericCast(value) as Int
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - Double : SelectValueResultType
|
||||
//
|
||||
//extension Double: SelectValueResultType {
|
||||
//
|
||||
// public static var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .doubleAttributeType
|
||||
// }
|
||||
//
|
||||
// public static func fromResultObject(_ result: Any) -> Double? {
|
||||
//
|
||||
// return (result as? NSNumber)?.doubleValue
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - Float: SelectValueResultType
|
||||
//
|
||||
//extension Float: SelectValueResultType {
|
||||
//
|
||||
// public static var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .floatAttributeType
|
||||
// }
|
||||
//
|
||||
// public static func fromResultObject(_ result: Any) -> Float? {
|
||||
//
|
||||
// return (result as? NSNumber)?.floatValue
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - String: SelectValueResultType
|
||||
//
|
||||
//extension String: SelectValueResultType {
|
||||
//
|
||||
// public static var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .stringAttributeType
|
||||
// }
|
||||
//
|
||||
// public static func fromResultObject(_ result: Any) -> String? {
|
||||
//
|
||||
// return result as? String
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - Date: SelectValueResultType
|
||||
//
|
||||
//extension Date: SelectValueResultType {
|
||||
//
|
||||
// public static var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .dateAttributeType
|
||||
// }
|
||||
//
|
||||
// public static func fromResultObject(_ result: Any) -> Date? {
|
||||
//
|
||||
// return result as? Date
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - Data: SelectValueResultType
|
||||
//
|
||||
//extension Data: SelectValueResultType {
|
||||
//
|
||||
// public static var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .binaryDataAttributeType
|
||||
// }
|
||||
//
|
||||
// public static func fromResultObject(_ result: Any) -> Data? {
|
||||
//
|
||||
// return result as? Data
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - NSNumber: SelectValueResultType
|
||||
//
|
||||
//extension NSNumber: SelectValueResultType {
|
||||
//
|
||||
// public class var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .integer64AttributeType
|
||||
// }
|
||||
//
|
||||
// public class func fromResultObject(_ result: Any) -> Self? {
|
||||
//
|
||||
// func forceCast<T: NSNumber>(_ object: Any) -> T? {
|
||||
//
|
||||
// return (object as? T)
|
||||
// }
|
||||
// return forceCast(result)
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - NSString: SelectValueResultType
|
||||
//
|
||||
//extension NSString: SelectValueResultType {
|
||||
//
|
||||
// public class var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .stringAttributeType
|
||||
// }
|
||||
//
|
||||
// public class func fromResultObject(_ result: Any) -> Self? {
|
||||
//
|
||||
// func forceCast<T: NSString>(_ object: Any) -> T? {
|
||||
//
|
||||
// return (object as? T)
|
||||
// }
|
||||
// return forceCast(result)
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - NSDecimalNumber: SelectValueResultType
|
||||
//
|
||||
//extension NSDecimalNumber {
|
||||
//
|
||||
// public override class var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .decimalAttributeType
|
||||
// }
|
||||
//
|
||||
// public override class func fromResultObject(_ result: Any) -> Self? {
|
||||
//
|
||||
// func forceCast<T: NSDecimalNumber>(_ object: Any) -> T? {
|
||||
//
|
||||
// return (object as? T)
|
||||
// }
|
||||
// return forceCast(result)
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - NSDate: SelectValueResultType
|
||||
//
|
||||
//extension NSDate: SelectValueResultType {
|
||||
//
|
||||
// public static var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .dateAttributeType
|
||||
// }
|
||||
//
|
||||
// public class func fromResultObject(_ result: Any) -> Self? {
|
||||
//
|
||||
// func forceCast<T: NSDate>(_ object: Any) -> T? {
|
||||
//
|
||||
// return (object as? T)
|
||||
// }
|
||||
// return forceCast(result)
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - NSData: SelectValueResultType
|
||||
//
|
||||
//extension NSData: SelectValueResultType {
|
||||
//
|
||||
// public static var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .binaryDataAttributeType
|
||||
// }
|
||||
//
|
||||
// public class func fromResultObject(_ result: Any) -> Self? {
|
||||
//
|
||||
// func forceCast<T: NSData>(_ object: Any) -> T? {
|
||||
//
|
||||
// return (object as? T)
|
||||
// }
|
||||
// return forceCast(result)
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - NSManagedObjectID: SelectValueResultType
|
||||
//
|
||||
//extension NSManagedObjectID: SelectValueResultType {
|
||||
//
|
||||
// public class var attributeType: NSAttributeType {
|
||||
//
|
||||
// return .objectIDAttributeType
|
||||
// }
|
||||
//
|
||||
// public class func fromResultObject(_ result: Any) -> Self? {
|
||||
//
|
||||
// func forceCast<T: NSManagedObjectID>(_ object: Any) -> T? {
|
||||
//
|
||||
// return (object as? T)
|
||||
// }
|
||||
// return forceCast(result)
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//// MARK: - NSManagedObjectID: SelectAttributesResultType
|
||||
//
|
||||
//extension NSDictionary: SelectAttributesResultType {
|
||||
//
|
||||
// // MARK: SelectAttributesResultType
|
||||
//
|
||||
// public class func fromResultObjects(_ result: [Any]) -> [[String: Any]] {
|
||||
//
|
||||
// return result as! [[String: Any]]
|
||||
// }
|
||||
//}
|
||||
// MARK: - NSManagedObjectID: SelectValueResultType
|
||||
|
||||
extension NSManagedObjectID: SelectValueResultType {
|
||||
|
||||
public static func cs_fromQueryResultNativeType(_ value: Any) -> Self? {
|
||||
|
||||
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - NSNumber: SelectValueResultType
|
||||
|
||||
extension NSNumber: SelectValueResultType {
|
||||
|
||||
public static func cs_fromQueryResultNativeType(_ value: Any) -> Self? {
|
||||
|
||||
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - NSString: SelectValueResultType
|
||||
|
||||
extension NSString: SelectValueResultType {
|
||||
|
||||
public static func cs_fromQueryResultNativeType(_ value: Any) -> Self? {
|
||||
|
||||
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - NSDate: SelectValueResultType
|
||||
|
||||
extension NSDate: SelectValueResultType {
|
||||
|
||||
public static func cs_fromQueryResultNativeType(_ value: Any) -> Self? {
|
||||
|
||||
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - NSData: SelectValueResultType
|
||||
|
||||
extension NSData: SelectValueResultType {
|
||||
|
||||
public static func cs_fromQueryResultNativeType(_ value: Any) -> Self? {
|
||||
|
||||
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Bool: SelectValueResultType
|
||||
|
||||
extension Bool: SelectValueResultType {
|
||||
|
||||
public static func cs_fromQueryResultNativeType(_ value: Any) -> Bool? {
|
||||
|
||||
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Int8: SelectValueResultType
|
||||
|
||||
extension Int8: SelectValueResultType {
|
||||
|
||||
public static func cs_fromQueryResultNativeType(_ value: Any) -> Int8? {
|
||||
|
||||
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Int16: SelectValueResultType
|
||||
|
||||
extension Int16: SelectValueResultType {
|
||||
|
||||
public static func cs_fromQueryResultNativeType(_ value: Any) -> Int16? {
|
||||
|
||||
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Int32: SelectValueResultType
|
||||
|
||||
extension Int32: SelectValueResultType {
|
||||
|
||||
public static func cs_fromQueryResultNativeType(_ value: Any) -> Int32? {
|
||||
|
||||
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Int64: SelectValueResultType
|
||||
|
||||
extension Int64: SelectValueResultType {
|
||||
|
||||
public static func cs_fromQueryResultNativeType(_ value: Any) -> Int64? {
|
||||
|
||||
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Int: SelectValueResultType
|
||||
|
||||
extension Int: SelectValueResultType {
|
||||
|
||||
public static func cs_fromQueryResultNativeType(_ value: Any) -> Int? {
|
||||
|
||||
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Double: SelectValueResultType
|
||||
|
||||
extension Double: SelectValueResultType {
|
||||
|
||||
public static func cs_fromQueryResultNativeType(_ value: Any) -> Double? {
|
||||
|
||||
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Float: SelectValueResultType
|
||||
|
||||
extension Float: SelectValueResultType {
|
||||
|
||||
public static func cs_fromQueryResultNativeType(_ value: Any) -> Float? {
|
||||
|
||||
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - CGFloat: SelectValueResultType
|
||||
|
||||
extension CGFloat: SelectValueResultType {
|
||||
|
||||
public static func cs_fromQueryResultNativeType(_ value: Any) -> CGFloat? {
|
||||
|
||||
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Date: SelectValueResultType
|
||||
|
||||
extension Date: SelectValueResultType {
|
||||
|
||||
public static func cs_fromQueryResultNativeType(_ value: Any) -> Date? {
|
||||
|
||||
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - String: SelectValueResultType
|
||||
|
||||
extension String: SelectValueResultType {
|
||||
|
||||
public static func cs_fromQueryResultNativeType(_ value: Any) -> String? {
|
||||
|
||||
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Data: SelectValueResultType
|
||||
|
||||
extension Data: SelectValueResultType {
|
||||
|
||||
public static func cs_fromQueryResultNativeType(_ value: Any) -> Data? {
|
||||
|
||||
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - NSDictionary: SelectAttributesResultType
|
||||
|
||||
extension NSDictionary: SelectAttributesResultType {
|
||||
|
||||
// MARK: SelectAttributesResultType
|
||||
|
||||
public static func cs_fromQueryResultsNativeType(_ result: [Any]) -> [[String : Any]] {
|
||||
|
||||
return result as! [[String: Any]]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Internal
|
||||
|
||||
@@ -205,7 +205,7 @@ public extension CoreStore {
|
||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||
*/
|
||||
public static func queryValue<T: NSManagedObject, U: CoreStoreQueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
|
||||
public static func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
|
||||
|
||||
return self.defaultStack.queryValue(from, selectClause, queryClauses)
|
||||
}
|
||||
@@ -220,7 +220,7 @@ public extension CoreStore {
|
||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||
*/
|
||||
public static func queryValue<T: NSManagedObject, U: CoreStoreQueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
|
||||
public static func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
|
||||
|
||||
return self.defaultStack.queryValue(from, selectClause, queryClauses)
|
||||
}
|
||||
|
||||
@@ -234,6 +234,28 @@ extension Bool: CoreStoreQueryableAttributeType {
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Int8
|
||||
|
||||
extension Int8: CoreStoreQueryableAttributeType {
|
||||
|
||||
public typealias QueryableNativeType = NSNumber
|
||||
|
||||
public static let cs_rawAttributeType: NSAttributeType = .integer16AttributeType
|
||||
|
||||
@inline(__always)
|
||||
public static func cs_fromQueryableNativeType(_ value: QueryableNativeType) -> Int8? {
|
||||
|
||||
return value.int8Value
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
public func cs_toQueryableNativeType() -> QueryableNativeType {
|
||||
|
||||
return self as NSNumber
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Int16
|
||||
|
||||
extension Int16: CoreStoreQueryableAttributeType {
|
||||
|
||||
@@ -250,7 +250,7 @@ extension DataStack: FetchableSource, QueryableSource {
|
||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||
*/
|
||||
public func queryValue<T: NSManagedObject, U: CoreStoreQueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
|
||||
public func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
|
||||
|
||||
CoreStore.assert(
|
||||
Thread.isMainThread,
|
||||
@@ -269,7 +269,7 @@ extension DataStack: FetchableSource, QueryableSource {
|
||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||
*/
|
||||
public func queryValue<T: NSManagedObject, U: CoreStoreQueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
|
||||
public func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
|
||||
|
||||
CoreStore.assert(
|
||||
Thread.isMainThread,
|
||||
|
||||
@@ -44,7 +44,7 @@ public protocol QueryableSource: class {
|
||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||
*/
|
||||
func queryValue<T: NSManagedObject, U: CoreStoreQueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U?
|
||||
func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U?
|
||||
|
||||
/**
|
||||
Queries aggregate values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
@@ -56,7 +56,7 @@ public protocol QueryableSource: class {
|
||||
- parameter queryClauses: a series of `QueryClause` instances for the query request. Accepts `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
- returns: the result of the the query. The type of the return value is specified by the generic type of the `Select<U>` parameter.
|
||||
*/
|
||||
func queryValue<T: NSManagedObject, U: CoreStoreQueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U?
|
||||
func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U?
|
||||
|
||||
/**
|
||||
Queries a dictionary of attribute values as specified by the `QueryClause`s. Requires at least a `Select` clause, and optional `Where`, `OrderBy`, `GroupBy`, and `Tweak` clauses.
|
||||
|
||||
@@ -238,13 +238,13 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
||||
// MARK: QueryableSource
|
||||
|
||||
@nonobjc
|
||||
public func queryValue<T: NSManagedObject, U: CoreStoreQueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
|
||||
public func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: QueryClause...) -> U? {
|
||||
|
||||
return self.queryValue(from, selectClause, queryClauses)
|
||||
}
|
||||
|
||||
@nonobjc
|
||||
public func queryValue<T: NSManagedObject, U: CoreStoreQueryableAttributeType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
|
||||
public func queryValue<T: NSManagedObject, U: SelectValueResultType>(_ from: From<T>, _ selectClause: Select<U>, _ queryClauses: [QueryClause]) -> U? {
|
||||
|
||||
let fetchRequest = CoreStoreFetchRequest()
|
||||
let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
||||
@@ -262,30 +262,6 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
||||
return self.queryValue(selectTerms, fetchRequest: fetchRequest)
|
||||
}
|
||||
|
||||
@nonobjc
|
||||
public func queryAttributes<T: NSManagedObject, U: CoreStoreQueryableAttributeType>(_ from: From<T>, _ selectClause: Select<[U]>, _ queryClauses: QueryClause...) -> [[String: Any]]? {
|
||||
|
||||
return self.queryAttributes(from, selectClause, queryClauses)
|
||||
}
|
||||
|
||||
@nonobjc
|
||||
public func queryAttributes<T: NSManagedObject, U: CoreStoreQueryableAttributeType>(_ from: From<T>, _ selectClause: Select<[U]>, _ queryClauses: [QueryClause]) -> [[String: Any]]? {
|
||||
|
||||
let fetchRequest = CoreStoreFetchRequest()
|
||||
let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
||||
|
||||
fetchRequest.fetchLimit = 0
|
||||
|
||||
selectClause.selectTerms.applyToFetchRequest(fetchRequest, owner: selectClause)
|
||||
queryClauses.forEach { $0.applyToFetchRequest(fetchRequest) }
|
||||
|
||||
guard storeFound else {
|
||||
|
||||
return nil
|
||||
}
|
||||
return self.queryAttributes(fetchRequest)
|
||||
}
|
||||
|
||||
@nonobjc
|
||||
public func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? {
|
||||
|
||||
@@ -439,7 +415,7 @@ internal extension NSManagedObjectContext {
|
||||
// MARK: Querying
|
||||
|
||||
@nonobjc
|
||||
internal func queryValue<U: CoreStoreQueryableAttributeType>(_ selectTerms: [SelectTerm], fetchRequest: NSFetchRequest<NSFetchRequestResult>) -> U? {
|
||||
internal func queryValue<U: SelectValueResultType>(_ selectTerms: [SelectTerm], fetchRequest: NSFetchRequest<NSFetchRequestResult>) -> U? {
|
||||
|
||||
var fetchResults: [Any]?
|
||||
var fetchError: Error?
|
||||
@@ -457,9 +433,9 @@ internal extension NSManagedObjectContext {
|
||||
if let fetchResults = fetchResults {
|
||||
|
||||
if let rawResult = fetchResults.first as? NSDictionary,
|
||||
let rawObject = rawResult[selectTerms.keyPathForFirstSelectTerm()] as? U.QueryableNativeType {
|
||||
let rawObject = rawResult[selectTerms.keyPathForFirstSelectTerm()] {
|
||||
|
||||
return U.cs_fromQueryableNativeType(rawObject)
|
||||
return Select<U>.ReturnType.cs_fromQueryResultNativeType(rawObject)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -522,7 +498,7 @@ internal extension NSManagedObjectContext {
|
||||
}
|
||||
if let fetchResults = fetchResults {
|
||||
|
||||
return Select<NSDictionary>.ReturnType.fromResultObjects(fetchResults)
|
||||
return Select<NSDictionary>.ReturnType.cs_fromQueryResultsNativeType(fetchResults)
|
||||
}
|
||||
|
||||
CoreStore.log(
|
||||
|
||||
@@ -361,7 +361,7 @@ public final class CSSelect: NSObject {
|
||||
|
||||
public init<T: SelectValueResultType>(_ swiftValue: Select<T>) {
|
||||
|
||||
self.attributeType = T.attributeType
|
||||
self.attributeType = T.cs_rawAttributeType
|
||||
self.selectTerms = swiftValue.selectTerms
|
||||
self.bridgeToSwift = swiftValue
|
||||
super.init()
|
||||
|
||||
Reference in New Issue
Block a user