From 74721b5c127a9158804b225f7ecdc683a93325fe Mon Sep 17 00:00:00 2001 From: John Estropia Date: Sat, 10 Oct 2020 16:55:35 +0900 Subject: [PATCH] allow ObjectSnapshot and ObjectPublisher as parameter to Where clauses --- Sources/KeyPath+Querying.swift | 66 ++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/Sources/KeyPath+Querying.swift b/Sources/KeyPath+Querying.swift index 1fd8ed2..ceaf7ae 100644 --- a/Sources/KeyPath+Querying.swift +++ b/Sources/KeyPath+Querying.swift @@ -267,6 +267,17 @@ public func == (_ keyPath: KeyPath return Where(keyPath._kvcKeyPathString!, isEqualTo: objectID) } +/** + Creates a `Where` clause by comparing if a property is equal to a value + ``` + let dog = dataStack.fetchOne(From().where(\.master == john)) + ``` + */ +public func == (_ keyPath: KeyPath, _ object: O) -> Where where O.ObjectType: NSManagedObject { + + return Where(keyPath._kvcKeyPathString!, isEqualTo: object.cs_id()) +} + /** Creates a `Where` clause by comparing if a property is not equal to a value ``` @@ -278,6 +289,17 @@ public func != (_ keyPath: KeyPath return !Where(keyPath._kvcKeyPathString!, isEqualTo: objectID) } +/** + Creates a `Where` clause by comparing if a property is not equal to a value + ``` + let dog = dataStack.fetchOne(From().where(\.master != john)) + ``` + */ +public func != (_ keyPath: KeyPath, _ object: O) -> Where where O.ObjectType: NSManagedObject { + + return !Where(keyPath._kvcKeyPathString!, isEqualTo: object.cs_id()) +} + /** Creates a `Where` clause by checking if a sequence contains a value of a property ``` @@ -303,6 +325,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 = dataStack.fetchOne(From().where(\.master == john)) + ``` + */ +public func == (_ keyPath: KeyPath>, _ object: O?) -> Where where O.ObjectType: NSManagedObject { + + return Where(keyPath._kvcKeyPathString!, isEqualTo: object?.cs_toRaw()) +} + /** Creates a `Where` clause by comparing if a property is not equal to a value ``` @@ -314,6 +347,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 = dataStack.fetchOne(From().where(\.master != john)) + ``` + */ +public func != (_ keyPath: KeyPath>, _ object: O?) -> Where where O.ObjectType: NSManagedObject { + + return !Where(keyPath._kvcKeyPathString!, isEqualTo: object?.cs_toRaw()) +} + /** Creates a `Where` clause by checking if a sequence contains a value of a property ``` @@ -690,6 +734,17 @@ public func == (_ keyPath: KeyPath(O.meta[keyPath: keyPath].keyPath, isEqualTo: object) } +/** + Creates a `Where` clause by comparing if a property is equal to a value + ``` + let dog = dataStack.fetchOne(From().where(\.master == john)) + ``` + */ +public func == (_ keyPath: KeyPath.Relationship>, _ object: R?) -> Where where D.DestinationObjectType == R.ObjectType { + + return Where(O.meta[keyPath: keyPath].keyPath, isEqualTo: object?.objectID()) +} + /** Creates a `Where` clause by comparing if a property is equal to a value ``` @@ -723,6 +778,17 @@ public func != (_ keyPath: KeyPath(O.meta[keyPath: keyPath].keyPath, isEqualTo: object) } +/** + Creates a `Where` clause by comparing if a property is not equal to a value + ``` + let dog = dataStack.fetchOne(From().where(\.master != john)) + ``` + */ +public func != (_ keyPath: KeyPath.Relationship>, _ object: R?) -> Where where D.DestinationObjectType == R.ObjectType { + + return !Where(O.meta[keyPath: keyPath].keyPath, isEqualTo: object?.objectID()) +} + /** Creates a `Where` clause by comparing if a property is not equal to a value ```