diff --git a/Sources/CoreStoreObject+Querying.swift b/Sources/CoreStoreObject+Querying.swift index 05630de..7896b9a 100644 --- a/Sources/CoreStoreObject+Querying.swift +++ b/Sources/CoreStoreObject+Querying.swift @@ -276,6 +276,82 @@ public extension ValueContainer.Optional { return !Where(attribute.keyPath, isEqualTo: value) } + /** + Creates a `Where` clause from a `CoreStoreObject.Value` property. + ``` + let person = CoreStore.fetchOne(From(), Person.where { $0.age < 20 }) + ``` + */ + @inline(__always) + public static func < (_ attribute: ValueContainer.Optional, _ value: V?) -> Where { + + if let value = value { + + return Where("%K < %@", attribute.keyPath, value) + } + else { + + return Where("%K < nil", attribute.keyPath) + } + } + + /** + Creates a `Where` clause from a `CoreStoreObject.Value` property. + ``` + let person = CoreStore.fetchOne(From(), Person.where { $0.age > 20 }) + ``` + */ + @inline(__always) + public static func > (_ attribute: ValueContainer.Optional, _ value: V?) -> Where { + + if let value = value { + + return Where("%K > %@", attribute.keyPath, value) + } + else { + + return Where("%K > nil", attribute.keyPath) + } + } + + /** + Creates a `Where` clause from a `CoreStoreObject.Value` property. + ``` + let person = CoreStore.fetchOne(From(), Person.where { $0.age <= 20 }) + ``` + */ + @inline(__always) + public static func <= (_ attribute: ValueContainer.Optional, _ value: V?) -> Where { + + if let value = value { + + return Where("%K <= %@", attribute.keyPath, value) + } + else { + + return Where("%K <= nil", attribute.keyPath) + } + } + + /** + Creates a `Where` clause from a `CoreStoreObject.Value` property. + ``` + let person = CoreStore.fetchOne(From(), Person.where { $0.age >= 20 }) + ``` + */ + @inline(__always) + public static func >= (_ attribute: ValueContainer.Optional, _ value: V?) -> Where { + + if let value = value { + + return Where("%K >= %@", attribute.keyPath, value) + } + else { + + return Where("%K >= nil", attribute.keyPath) + } + } + /** Creates a `Where` clause from a `CoreStoreObject.Value` property. ```