mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-11 21:11:58 +01:00
WIP: typesafe queries
This commit is contained in:
@@ -168,7 +168,7 @@ public extension ManagedObjectProtocol where Self: CoreStoreManagedObject {
|
||||
|
||||
public typealias Attribute = AttributeContainer<Self>
|
||||
|
||||
public static var meta: Self {
|
||||
static var meta: Self {
|
||||
|
||||
return self.init(nil)
|
||||
}
|
||||
@@ -184,6 +184,12 @@ public extension ManagedObjectProtocol where Self: CoreStoreManagedObject {
|
||||
|
||||
return attribute(self.meta).keyPath
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
public static func `where`(_ condition: (Self) -> Where) -> Where {
|
||||
|
||||
return condition(self.meta)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -211,43 +217,36 @@ public postfix func * <O: ManagedObjectProtocol, V: ImportableAttributeType>(_ a
|
||||
|
||||
public extension AttributeContainer.Required where V: CVarArg {
|
||||
|
||||
public static func == (_ attribute: AttributeContainer<O>.Required<V>, _ value: V) -> NSPredicate {
|
||||
public static func == (_ attribute: AttributeContainer<O>.Required<V>, _ value: V) -> Where {
|
||||
|
||||
return NSPredicate(format: "%K == %@", argumentArray: [attribute.keyPath, value])
|
||||
return Where(attribute.keyPath, isEqualTo: value)
|
||||
}
|
||||
public static func < (_ attribute: AttributeContainer<O>.Required<V>, _ value: V) -> NSPredicate {
|
||||
public static func < (_ attribute: AttributeContainer<O>.Required<V>, _ value: V) -> Where {
|
||||
|
||||
return NSPredicate(format: "%K < %@", argumentArray: [attribute.keyPath, value])
|
||||
return Where("%K < %@", attribute.keyPath, value)
|
||||
}
|
||||
public static func > (_ attribute: AttributeContainer<O>.Required<V>, _ value: V) -> NSPredicate {
|
||||
public static func > (_ attribute: AttributeContainer<O>.Required<V>, _ value: V) -> Where {
|
||||
|
||||
return NSPredicate(format: "%K > %@", argumentArray: [attribute.keyPath, value])
|
||||
return Where("%K > %@", attribute.keyPath, value)
|
||||
}
|
||||
public static func <= (_ attribute: AttributeContainer<O>.Required<V>, _ value: V) -> NSPredicate {
|
||||
public static func <= (_ attribute: AttributeContainer<O>.Required<V>, _ value: V) -> Where {
|
||||
|
||||
return NSPredicate(format: "%K <= %@", argumentArray: [attribute.keyPath, value])
|
||||
return Where("%K <= %@", attribute.keyPath, value)
|
||||
}
|
||||
public static func >= (_ attribute: AttributeContainer<O>.Required<V>, _ value: V) -> NSPredicate {
|
||||
public static func >= (_ attribute: AttributeContainer<O>.Required<V>, _ value: V) -> Where {
|
||||
|
||||
return NSPredicate(format: "%K >= %@", argumentArray: [attribute.keyPath, value])
|
||||
return Where("%K >= %@", attribute.keyPath, value)
|
||||
}
|
||||
public static func != (_ attribute: AttributeContainer<O>.Required<V>, _ value: V) -> NSPredicate {
|
||||
public static func != (_ attribute: AttributeContainer<O>.Required<V>, _ value: V) -> Where {
|
||||
|
||||
return NSPredicate(format: "%K != %@", argumentArray: [attribute.keyPath, value])
|
||||
return Where("%K != %@", attribute.keyPath, value)
|
||||
}
|
||||
}
|
||||
public extension AttributeContainer.Optional where V: CVarArg {
|
||||
|
||||
public static func == (_ attribute: AttributeContainer<O>.Optional<V>, _ value: V?) -> NSPredicate {
|
||||
public static func == (_ attribute: AttributeContainer<O>.Optional<V>, _ value: V?) -> Where {
|
||||
|
||||
if let value = value {
|
||||
|
||||
return NSPredicate(format: "%K == %@", argumentArray: [attribute.keyPath, value])
|
||||
}
|
||||
else {
|
||||
|
||||
return NSPredicate(format: "%K == nil", attribute.keyPath)
|
||||
}
|
||||
return Where(attribute.keyPath, isEqualTo: value)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user