mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-04-23 01:08:31 +02: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.
|
- 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.
|
- 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(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
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.
|
- 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.
|
- 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(
|
CoreStore.assert(
|
||||||
self.isRunningInAllowedQueue(),
|
self.isRunningInAllowedQueue(),
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import CoreGraphics
|
||||||
import CoreData
|
import CoreData
|
||||||
|
|
||||||
|
|
||||||
@@ -32,34 +33,31 @@ import CoreData
|
|||||||
/**
|
/**
|
||||||
The `SelectResultType` protocol is implemented by return types supported by the `Select` clause.
|
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
|
// MARK: - SelectAttributesResultType
|
||||||
//
|
|
||||||
///**
|
|
||||||
// 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
|
The `SelectAttributesResultType` protocol is implemented by return types supported by the `queryAttributes(...)` methods.
|
||||||
//
|
*/
|
||||||
///**
|
public protocol SelectAttributesResultType: SelectResultType {
|
||||||
// The `SelectValueResultType` protocol is implemented by return types supported by the `queryAttributes(...)` methods.
|
|
||||||
// */
|
static func cs_fromQueryResultsNativeType(_ result: [Any]) -> [[String: Any]]
|
||||||
//public protocol SelectAttributesResultType: SelectResultType {
|
}
|
||||||
//
|
|
||||||
// static func fromResultObjects(_ result: [Any]) -> [[String: Any]]
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
||||||
// MARK: - SelectTerm
|
// MARK: - SelectTerm
|
||||||
@@ -338,7 +336,7 @@ public enum SelectTerm: ExpressibleByStringLiteral, Hashable {
|
|||||||
|
|
||||||
- parameter sortDescriptors: a series of `NSSortDescriptor`s
|
- 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
|
The `SelectResultType` type for the query's return value
|
||||||
@@ -369,7 +367,7 @@ public struct Select<T: CoreStoreQueryableAttributeType>: Hashable {
|
|||||||
|
|
||||||
// MARK: Equatable
|
// 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
|
return lhs.selectTerms == rhs.selectTerms
|
||||||
}
|
}
|
||||||
@@ -397,340 +395,204 @@ public extension Select where T: NSManagedObjectID {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//// MARK: - Bool: SelectValueResultType
|
// MARK: - NSManagedObjectID: SelectValueResultType
|
||||||
//
|
|
||||||
//extension Bool: SelectValueResultType {
|
extension NSManagedObjectID: SelectValueResultType {
|
||||||
//
|
|
||||||
// public static var attributeType: NSAttributeType {
|
public static func cs_fromQueryResultNativeType(_ value: Any) -> Self? {
|
||||||
//
|
|
||||||
// return .booleanAttributeType
|
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||||
// }
|
}
|
||||||
//
|
}
|
||||||
// public static func fromResultObject(_ result: Any) -> Bool? {
|
|
||||||
// switch result {
|
|
||||||
//
|
// MARK: - NSNumber: SelectValueResultType
|
||||||
// case let decimal as NSDecimalNumber:
|
|
||||||
// // iOS: NSDecimalNumber(string: "0.5").boolValue // true
|
extension NSNumber: SelectValueResultType {
|
||||||
// // OSX: NSDecimalNumber(string: "0.5").boolValue // false
|
|
||||||
// return NSNumber(value: decimal.doubleValue).boolValue
|
public static func cs_fromQueryResultNativeType(_ value: Any) -> Self? {
|
||||||
//
|
|
||||||
// case let number as NSNumber:
|
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||||
// return number.boolValue
|
}
|
||||||
//
|
}
|
||||||
// default:
|
|
||||||
// return nil
|
|
||||||
// }
|
// MARK: - NSString: SelectValueResultType
|
||||||
// }
|
|
||||||
//}
|
extension NSString: SelectValueResultType {
|
||||||
//
|
|
||||||
//
|
public static func cs_fromQueryResultNativeType(_ value: Any) -> Self? {
|
||||||
//// MARK: - Int8: SelectValueResultType
|
|
||||||
//
|
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||||
//extension Int8: SelectValueResultType {
|
}
|
||||||
//
|
}
|
||||||
// public static var attributeType: NSAttributeType {
|
|
||||||
//
|
|
||||||
// return .integer64AttributeType
|
// MARK: - NSDate: SelectValueResultType
|
||||||
// }
|
|
||||||
//
|
extension NSDate: SelectValueResultType {
|
||||||
// public static func fromResultObject(_ result: Any) -> Int8? {
|
|
||||||
//
|
public static func cs_fromQueryResultNativeType(_ value: Any) -> Self? {
|
||||||
// guard let value = (result as? NSNumber)?.int64Value else {
|
|
||||||
//
|
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||||
// return nil
|
}
|
||||||
// }
|
}
|
||||||
// return numericCast(value) as Int8
|
|
||||||
// }
|
|
||||||
//}
|
// MARK: - NSData: SelectValueResultType
|
||||||
//
|
|
||||||
//
|
extension NSData: SelectValueResultType {
|
||||||
//// MARK: - Int16: SelectValueResultType
|
|
||||||
//
|
public static func cs_fromQueryResultNativeType(_ value: Any) -> Self? {
|
||||||
//extension Int16: SelectValueResultType {
|
|
||||||
//
|
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||||
// public static var attributeType: NSAttributeType {
|
}
|
||||||
//
|
}
|
||||||
// return .integer64AttributeType
|
|
||||||
// }
|
|
||||||
//
|
// MARK: - Bool: SelectValueResultType
|
||||||
// public static func fromResultObject(_ result: Any) -> Int16? {
|
|
||||||
//
|
extension Bool: SelectValueResultType {
|
||||||
// guard let value = (result as? NSNumber)?.int64Value else {
|
|
||||||
//
|
public static func cs_fromQueryResultNativeType(_ value: Any) -> Bool? {
|
||||||
// return nil
|
|
||||||
// }
|
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||||
// return numericCast(value) as Int16
|
}
|
||||||
// }
|
}
|
||||||
//}
|
|
||||||
//
|
|
||||||
//
|
// MARK: - Int8: SelectValueResultType
|
||||||
//// MARK: - Int32: SelectValueResultType
|
|
||||||
//
|
extension Int8: SelectValueResultType {
|
||||||
//extension Int32: SelectValueResultType {
|
|
||||||
//
|
public static func cs_fromQueryResultNativeType(_ value: Any) -> Int8? {
|
||||||
// public static var attributeType: NSAttributeType {
|
|
||||||
//
|
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||||
// return .integer64AttributeType
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public static func fromResultObject(_ result: Any) -> Int32? {
|
|
||||||
//
|
// MARK: - Int16: SelectValueResultType
|
||||||
// guard let value = (result as? NSNumber)?.int64Value else {
|
|
||||||
//
|
extension Int16: SelectValueResultType {
|
||||||
// return nil
|
|
||||||
// }
|
public static func cs_fromQueryResultNativeType(_ value: Any) -> Int16? {
|
||||||
// return numericCast(value) as Int32
|
|
||||||
// }
|
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||||
//}
|
}
|
||||||
//
|
}
|
||||||
//
|
|
||||||
//// MARK: - Int64: SelectValueResultType
|
|
||||||
//
|
// MARK: - Int32: SelectValueResultType
|
||||||
//extension Int64: SelectValueResultType {
|
|
||||||
//
|
extension Int32: SelectValueResultType {
|
||||||
// public static var attributeType: NSAttributeType {
|
|
||||||
//
|
public static func cs_fromQueryResultNativeType(_ value: Any) -> Int32? {
|
||||||
// return .integer64AttributeType
|
|
||||||
// }
|
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||||
//
|
}
|
||||||
// public static func fromResultObject(_ result: Any) -> Int64? {
|
}
|
||||||
//
|
|
||||||
// return (result as? NSNumber)?.int64Value
|
|
||||||
// }
|
// MARK: - Int64: SelectValueResultType
|
||||||
//}
|
|
||||||
//
|
extension Int64: SelectValueResultType {
|
||||||
//
|
|
||||||
//// MARK: - Int: SelectValueResultType
|
public static func cs_fromQueryResultNativeType(_ value: Any) -> Int64? {
|
||||||
//
|
|
||||||
//extension Int: SelectValueResultType {
|
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||||
//
|
}
|
||||||
// public static var attributeType: NSAttributeType {
|
}
|
||||||
//
|
|
||||||
// return .integer64AttributeType
|
|
||||||
// }
|
// MARK: - Int: SelectValueResultType
|
||||||
//
|
|
||||||
// public static func fromResultObject(_ result: Any) -> Int? {
|
extension Int: SelectValueResultType {
|
||||||
//
|
|
||||||
// guard let value = (result as? NSNumber)?.int64Value else {
|
public static func cs_fromQueryResultNativeType(_ value: Any) -> Int? {
|
||||||
//
|
|
||||||
// return nil
|
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||||
// }
|
}
|
||||||
// return numericCast(value) as Int
|
}
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
// MARK: - Double: SelectValueResultType
|
||||||
//
|
|
||||||
//// MARK: - Double : SelectValueResultType
|
extension Double: SelectValueResultType {
|
||||||
//
|
|
||||||
//extension Double: SelectValueResultType {
|
public static func cs_fromQueryResultNativeType(_ value: Any) -> Double? {
|
||||||
//
|
|
||||||
// public static var attributeType: NSAttributeType {
|
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||||
//
|
}
|
||||||
// return .doubleAttributeType
|
}
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public static func fromResultObject(_ result: Any) -> Double? {
|
// MARK: - Float: SelectValueResultType
|
||||||
//
|
|
||||||
// return (result as? NSNumber)?.doubleValue
|
extension Float: SelectValueResultType {
|
||||||
// }
|
|
||||||
//}
|
public static func cs_fromQueryResultNativeType(_ value: Any) -> Float? {
|
||||||
//
|
|
||||||
//
|
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||||
//// MARK: - Float: SelectValueResultType
|
}
|
||||||
//
|
}
|
||||||
//extension Float: SelectValueResultType {
|
|
||||||
//
|
|
||||||
// public static var attributeType: NSAttributeType {
|
// MARK: - CGFloat: SelectValueResultType
|
||||||
//
|
|
||||||
// return .floatAttributeType
|
extension CGFloat: SelectValueResultType {
|
||||||
// }
|
|
||||||
//
|
public static func cs_fromQueryResultNativeType(_ value: Any) -> CGFloat? {
|
||||||
// public static func fromResultObject(_ result: Any) -> Float? {
|
|
||||||
//
|
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||||
// return (result as? NSNumber)?.floatValue
|
}
|
||||||
// }
|
}
|
||||||
//}
|
|
||||||
//
|
|
||||||
//
|
// MARK: - Date: SelectValueResultType
|
||||||
//// MARK: - String: SelectValueResultType
|
|
||||||
//
|
extension Date: SelectValueResultType {
|
||||||
//extension String: SelectValueResultType {
|
|
||||||
//
|
public static func cs_fromQueryResultNativeType(_ value: Any) -> Date? {
|
||||||
// public static var attributeType: NSAttributeType {
|
|
||||||
//
|
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||||
// return .stringAttributeType
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public static func fromResultObject(_ result: Any) -> String? {
|
|
||||||
//
|
// MARK: - String: SelectValueResultType
|
||||||
// return result as? String
|
|
||||||
// }
|
extension String: SelectValueResultType {
|
||||||
//}
|
|
||||||
//
|
public static func cs_fromQueryResultNativeType(_ value: Any) -> String? {
|
||||||
//
|
|
||||||
//// MARK: - Date: SelectValueResultType
|
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||||
//
|
}
|
||||||
//extension Date: SelectValueResultType {
|
}
|
||||||
//
|
|
||||||
// public static var attributeType: NSAttributeType {
|
|
||||||
//
|
// MARK: - Data: SelectValueResultType
|
||||||
// return .dateAttributeType
|
|
||||||
// }
|
extension Data: SelectValueResultType {
|
||||||
//
|
|
||||||
// public static func fromResultObject(_ result: Any) -> Date? {
|
public static func cs_fromQueryResultNativeType(_ value: Any) -> Data? {
|
||||||
//
|
|
||||||
// return result as? Date
|
return (value as? QueryableNativeType).flatMap(self.cs_fromQueryableNativeType)
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//
|
|
||||||
//// MARK: - Data: SelectValueResultType
|
// MARK: - NSDictionary: SelectAttributesResultType
|
||||||
//
|
|
||||||
//extension Data: SelectValueResultType {
|
extension NSDictionary: SelectAttributesResultType {
|
||||||
//
|
|
||||||
// public static var attributeType: NSAttributeType {
|
// MARK: SelectAttributesResultType
|
||||||
//
|
|
||||||
// return .binaryDataAttributeType
|
public static func cs_fromQueryResultsNativeType(_ result: [Any]) -> [[String : Any]] {
|
||||||
// }
|
|
||||||
//
|
return result as! [[String: Any]]
|
||||||
// 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: - Internal
|
// 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.
|
- 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.
|
- 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)
|
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.
|
- 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.
|
- 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)
|
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
|
// MARK: - Int16
|
||||||
|
|
||||||
extension Int16: CoreStoreQueryableAttributeType {
|
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.
|
- 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.
|
- 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(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
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.
|
- 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.
|
- 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(
|
CoreStore.assert(
|
||||||
Thread.isMainThread,
|
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.
|
- 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.
|
- 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.
|
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.
|
- 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.
|
- 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.
|
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
|
// MARK: QueryableSource
|
||||||
|
|
||||||
@nonobjc
|
@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)
|
return self.queryValue(from, selectClause, queryClauses)
|
||||||
}
|
}
|
||||||
|
|
||||||
@nonobjc
|
@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 fetchRequest = CoreStoreFetchRequest()
|
||||||
let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
let storeFound = from.applyToFetchRequest(fetchRequest, context: self)
|
||||||
@@ -262,30 +262,6 @@ extension NSManagedObjectContext: FetchableSource, QueryableSource {
|
|||||||
return self.queryValue(selectTerms, fetchRequest: fetchRequest)
|
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
|
@nonobjc
|
||||||
public func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? {
|
public func queryAttributes<T: NSManagedObject>(_ from: From<T>, _ selectClause: Select<NSDictionary>, _ queryClauses: QueryClause...) -> [[String: Any]]? {
|
||||||
|
|
||||||
@@ -439,7 +415,7 @@ internal extension NSManagedObjectContext {
|
|||||||
// MARK: Querying
|
// MARK: Querying
|
||||||
|
|
||||||
@nonobjc
|
@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 fetchResults: [Any]?
|
||||||
var fetchError: Error?
|
var fetchError: Error?
|
||||||
@@ -457,9 +433,9 @@ internal extension NSManagedObjectContext {
|
|||||||
if let fetchResults = fetchResults {
|
if let fetchResults = fetchResults {
|
||||||
|
|
||||||
if let rawResult = fetchResults.first as? NSDictionary,
|
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
|
return nil
|
||||||
}
|
}
|
||||||
@@ -522,7 +498,7 @@ internal extension NSManagedObjectContext {
|
|||||||
}
|
}
|
||||||
if let fetchResults = fetchResults {
|
if let fetchResults = fetchResults {
|
||||||
|
|
||||||
return Select<NSDictionary>.ReturnType.fromResultObjects(fetchResults)
|
return Select<NSDictionary>.ReturnType.cs_fromQueryResultsNativeType(fetchResults)
|
||||||
}
|
}
|
||||||
|
|
||||||
CoreStore.log(
|
CoreStore.log(
|
||||||
|
|||||||
@@ -361,7 +361,7 @@ public final class CSSelect: NSObject {
|
|||||||
|
|
||||||
public init<T: SelectValueResultType>(_ swiftValue: Select<T>) {
|
public init<T: SelectValueResultType>(_ swiftValue: Select<T>) {
|
||||||
|
|
||||||
self.attributeType = T.attributeType
|
self.attributeType = T.cs_rawAttributeType
|
||||||
self.selectTerms = swiftValue.selectTerms
|
self.selectTerms = swiftValue.selectTerms
|
||||||
self.bridgeToSwift = swiftValue
|
self.bridgeToSwift = swiftValue
|
||||||
super.init()
|
super.init()
|
||||||
|
|||||||
Reference in New Issue
Block a user