diff --git a/Sources/KeyPath+Querying.swift b/Sources/KeyPath+Querying.swift index f9a120c..3082303 100644 --- a/Sources/KeyPath+Querying.swift +++ b/Sources/KeyPath+Querying.swift @@ -76,6 +76,17 @@ public func == (_ key return Where(keyPath._kvcKeyPathString!, isEqualTo: value) } +/** + Creates a `Where` clause by comparing if a property is equal to a value + ``` + let person = CoreStore.fetchOne(From().where(\.nickname == nil)) + ``` + */ +public func == (_ keyPath: KeyPath>, _ null: Void?) -> Where { + + return Where("%K == nil", keyPath._kvcKeyPathString!) +} + /** Creates a `Where` clause by comparing if a property is not equal to a value ``` @@ -87,6 +98,17 @@ public func != (_ key return !Where(keyPath._kvcKeyPathString!, isEqualTo: value) } +/** + Creates a `Where` clause by comparing if a property is not equal to a value + ``` + let person = CoreStore.fetchOne(From().where(\.nickname != nil)) + ``` + */ +public func != (_ keyPath: KeyPath>, _ null: Void?) -> Where { + + return Where("%K != nil", keyPath._kvcKeyPathString!) +} + /** Creates a `Where` clause by checking if a sequence contains the value of a property ``` @@ -166,6 +188,17 @@ public func < (_ key } } +/** + Creates a `Where` clause by comparing if a property is less than a value + ``` + let person = CoreStore.fetchOne(From().where(\.age < 20)) + ``` + */ +public func < (_ keyPath: KeyPath>, _ null: Void?) -> Where { + + return Where("%K < nil", keyPath._kvcKeyPathString!) +} + /** Creates a `Where` clause by comparing if a property is greater than a value ``` @@ -184,6 +217,17 @@ public func > (_ key } } +/** + Creates a `Where` clause by comparing if a property is greater than a value + ``` + let person = CoreStore.fetchOne(From().where(\.age > nil)) + ``` + */ +public func > (_ keyPath: KeyPath>, _ null: Void?) -> Where { + + return Where("%K > nil", keyPath._kvcKeyPathString!) +} + /** Creates a `Where` clause by comparing if a property is less than or equal to a value ``` @@ -202,6 +246,17 @@ public func <= (_ ke } } +/** + Creates a `Where` clause by comparing if a property is less than or equal to a value + ``` + let person = CoreStore.fetchOne(From().where(\.age <= nil)) + ``` + */ +public func <= (_ keyPath: KeyPath>, _ null: Void?) -> Where { + + return Where("%K <= nil", keyPath._kvcKeyPathString!) +} + /** Creates a `Where` clause by comparing if a property is greater than or equal to a value ``` @@ -220,6 +275,17 @@ public func >= (_ ke } } +/** + Creates a `Where` clause by comparing if a property is greater than or equal to a value + ``` + let person = CoreStore.fetchOne(From().where(\.age >= nil)) + ``` + */ +public func >= (_ keyPath: KeyPath>, _ null: Void?) -> Where { + + return Where("%K >= nil", keyPath._kvcKeyPathString!) +} + // MARK: - KeyPath where Root: NSManagedObject, Value: NSManagedObject @@ -303,6 +369,17 @@ public func == (_ keyPath: KeyPath(keyPath._kvcKeyPathString!, isEqualTo: object) } +/** + Creates a `Where` clause by comparing if a property is equal to a value + ``` + let dog = CoreStore.fetchOne(From().where(\.master == nil)) + ``` + */ +public func == (_ keyPath: KeyPath>, _ null: Void?) -> Where { + + return Where("%K == nil", keyPath._kvcKeyPathString!) +} + /** Creates a `Where` clause by comparing if a property is not equal to a value ``` @@ -314,6 +391,17 @@ public func != (_ keyPath: KeyPath(keyPath._kvcKeyPathString!, isEqualTo: object) } +/** + Creates a `Where` clause by comparing if a property is not equal to a value + ``` + let dog = CoreStore.fetchOne(From().where(\.master != nil)) + ``` + */ +public func != (_ keyPath: KeyPath>, _ null: Void?) -> Where { + + return Where("%K != nil", keyPath._kvcKeyPathString!) +} + /** Creates a `Where` clause by checking if a sequence contains a value of a property ``` @@ -408,6 +496,17 @@ public func == (_ keyPath: KeyPath.Optional>, _ va return Where(O.meta[keyPath: keyPath].keyPath, isEqualTo: value) } +/** + Creates a `Where` clause by comparing if a property is equal to a value + ``` + let person = CoreStore.fetchOne(From().where(\.nickname == nil)) + ``` + */ +public func == (_ keyPath: KeyPath.Optional>, _ null: Void?) -> Where { + + return Where("%K == nil", O.meta[keyPath: keyPath].keyPath) +} + /** Creates a `Where` clause by comparing if a property is not equal to a value ``` @@ -419,6 +518,17 @@ public func != (_ keyPath: KeyPath.Optional>, _ va return !Where(O.meta[keyPath: keyPath].keyPath, isEqualTo: value) } +/** + Creates a `Where` clause by comparing if a property is not equal to a value + ``` + let person = CoreStore.fetchOne(From().where(\.nickname != nil)) + ``` + */ +public func != (_ keyPath: KeyPath.Optional>, _ null: Void?) -> Where { + + return Where("%K != nil", O.meta[keyPath: keyPath].keyPath) +} + /** Creates a `Where` clause by checking if a sequence contains the value of a property ``` @@ -498,6 +608,17 @@ public func < (_ keyPath: KeyPath.Optional>, _ val } } +/** + Creates a `Where` clause by comparing if a property is less than a value + ``` + let person = CoreStore.fetchOne(From().where(\.age < nil)) + ``` + */ +public func < (_ keyPath: KeyPath.Optional>, _ null: Void?) -> Where { + + return Where("%K < nil", O.meta[keyPath: keyPath].keyPath) +} + /** Creates a `Where` clause by comparing if a property is greater than a value ``` @@ -516,6 +637,17 @@ public func > (_ keyPath: KeyPath.Optional>, _ val } } +/** + Creates a `Where` clause by comparing if a property is greater than a value + ``` + let person = CoreStore.fetchOne(From().where(\.age > nil)) + ``` + */ +public func > (_ keyPath: KeyPath.Optional>, _ null: Void?) -> Where { + + return Where("%K > nil", O.meta[keyPath: keyPath].keyPath) +} + /** Creates a `Where` clause by comparing if a property is less than or equal to a value ``` @@ -534,6 +666,17 @@ public func <= (_ keyPath: KeyPath.Optional>, _ va } } +/** + Creates a `Where` clause by comparing if a property is less than or equal to a value + ``` + let person = CoreStore.fetchOne(From().where(\.age <= nil)) + ``` + */ +public func <= (_ keyPath: KeyPath.Optional>, _ null: Void?) -> Where { + + return Where("%K <= nil", O.meta[keyPath: keyPath].keyPath) +} + /** Creates a `Where` clause by comparing if a property is greater than or equal to a value ``` @@ -552,6 +695,17 @@ public func >= (_ keyPath: KeyPath.Optional>, _ va } } +/** + Creates a `Where` clause by comparing if a property is greater than or equal to a value + ``` + let person = CoreStore.fetchOne(From().where(\.age >= nil)) + ``` + */ +public func >= (_ keyPath: KeyPath.Optional>, _ null: Void?) -> Where { + + return Where("%K >= nil", O.meta[keyPath: keyPath].keyPath) +} + // MARK: - KeyPath where Root: CoreStoreObject, Value: RelationshipContainer.ToOne @@ -577,6 +731,17 @@ public func == (_ keyPath: KeyPath.ToOne>, return Where(O.meta[keyPath: keyPath].keyPath, isEqualTo: object) } +/** + Creates a `Where` clause by comparing if a property is equal to a value + ``` + let dog = CoreStore.fetchOne(From().where(\.master == nil)) + ``` + */ +public func == (_ keyPath: KeyPath.ToOne>, _ null: Void?) -> Where { + + return Where("%K == nil", O.meta[keyPath: keyPath].keyPath) +} + /** Creates a `Where` clause by comparing if a property is not equal to a value ``` @@ -599,6 +764,17 @@ public func != (_ keyPath: KeyPath.ToOne>, return !Where(O.meta[keyPath: keyPath].keyPath, isEqualTo: object) } +/** + Creates a `Where` clause by comparing if a property is not equal to a value + ``` + let dog = CoreStore.fetchOne(From().where(\.master != nil)) + ``` + */ +public func != (_ keyPath: KeyPath.ToOne>, _ null: Void?) -> Where { + + return Where("%K != nil", O.meta[keyPath: keyPath].keyPath) +} + /** Creates a `Where` clause by checking if a sequence contains a value of a property ``` diff --git a/Sources/Where.swift b/Sources/Where.swift index 9ec9329..3f53808 100644 --- a/Sources/Where.swift +++ b/Sources/Where.swift @@ -158,9 +158,9 @@ public struct Where: WhereClauseType, FetchClause, QueryClause Initializes a `Where` clause that compares equality to `nil` - parameter keyPath: the keyPath to compare with - - parameter value: the arguments for the `==` operator + - parameter null: the arguments for the `==` operator */ - public init(_ keyPath: KeyPathString, isEqualTo value: Void?) { + public init(_ keyPath: KeyPathString, isEqualTo null: Void?) { self.init(NSPredicate(format: "\(keyPath) == nil")) } @@ -303,22 +303,22 @@ public extension Where where D: NSManagedObject { Initializes a `Where` clause that compares equality to `nil` - parameter keyPath: the keyPath to compare with - - parameter value: the arguments for the `==` operator + - parameter null: the arguments for the `==` operator */ - public init(_ keyPath: KeyPath, isEqualTo value: Void?) { + public init(_ keyPath: KeyPath, isEqualTo null: Void?) { - self.init(keyPath._kvcKeyPathString!, isEqualTo: value) + self.init(keyPath._kvcKeyPathString!, isEqualTo: null) } /** Initializes a `Where` clause that compares equality to `nil` - parameter keyPath: the keyPath to compare with - - parameter value: the arguments for the `==` operator + - parameter null: the arguments for the `==` operator */ - public init(_ keyPath: KeyPath, isEqualTo value: Void?) { + public init(_ keyPath: KeyPath, isEqualTo null: Void?) { - self.init(keyPath._kvcKeyPathString!, isEqualTo: value) + self.init(keyPath._kvcKeyPathString!, isEqualTo: null) } /** @@ -397,22 +397,22 @@ public extension Where where D: CoreStoreObject { Initializes a `Where` clause that compares equality to `nil` - parameter keyPath: the keyPath to compare with - - parameter value: the arguments for the `==` operator + - parameter null: the arguments for the `==` operator */ - public init(_ keyPath: KeyPath.Optional>, isEqualTo value: Void?) { + public init(_ keyPath: KeyPath.Optional>, isEqualTo null: Void?) { - self.init(D.meta[keyPath: keyPath].keyPath, isEqualTo: value) + self.init(D.meta[keyPath: keyPath].keyPath, isEqualTo: null) } /** Initializes a `Where` clause that compares equality to `nil` - parameter keyPath: the keyPath to compare with - - parameter value: the arguments for the `==` operator + - parameter null: the arguments for the `==` operator */ - public init(_ keyPath: KeyPath.ToOne>, isEqualTo value: Void?) { + public init(_ keyPath: KeyPath.ToOne>, isEqualTo null: Void?) { - self.init(D.meta[keyPath: keyPath].keyPath, isEqualTo: value) + self.init(D.meta[keyPath: keyPath].keyPath, isEqualTo: null) } /**