// // KeyPath+Querying.swift // CoreStore // // Copyright © 2018 John Rommel Estropia // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // import CoreData import Foundation // MARK: - KeyPath where Root: NSManagedObject, Value: QueryableAttributeType & Equatable /** Creates a `Where` clause by comparing if a property is equal to a value ``` let person = dataStack.fetchOne(From().where(\.nickname == "John")) ``` */ public func == (_ keyPath: KeyPath, _ value: V) -> Where { return Where(keyPath._kvcKeyPathString!, isEqualTo: value) } /** Creates a `Where` clause by comparing if a property is not equal to a value ``` let person = dataStack.fetchOne(From().where(\.nickname != "John")) ``` */ public func != (_ keyPath: KeyPath, _ value: V) -> Where { return !Where(keyPath._kvcKeyPathString!, isEqualTo: value) } /** Creates a `Where` clause by checking if a sequence contains the value of a property ``` let dog = dataStack.fetchOne(From().where(["Pluto", "Snoopy", "Scooby"] ~= \.nickname)) ``` */ public func ~= (_ sequence: S, _ keyPath: KeyPath) -> Where where S.Iterator.Element == V { return Where(keyPath._kvcKeyPathString!, isMemberOf: sequence) } // MARK: - KeyPath where Root: NSManagedObject, Value: Optional /** Creates a `Where` clause by comparing if a property is equal to a value ``` let person = dataStack.fetchOne(From().where(\.nickname == "John")) ``` */ public func == (_ keyPath: KeyPath>, _ value: V?) -> Where { return Where(keyPath._kvcKeyPathString!, isEqualTo: value) } /** Creates a `Where` clause by comparing if a property is not equal to a value ``` let person = dataStack.fetchOne(From().where(\.nickname != "John")) ``` */ public func != (_ keyPath: KeyPath>, _ value: V?) -> Where { return !Where(keyPath._kvcKeyPathString!, isEqualTo: value) } /** Creates a `Where` clause by checking if a sequence contains the value of a property ``` let dog = dataStack.fetchOne(From().where(["Pluto", "Snoopy", "Scooby"] ~= \.nickname)) ``` */ public func ~= (_ sequence: S, _ keyPath: KeyPath>) -> Where where S.Iterator.Element == V { return Where(keyPath._kvcKeyPathString!, isMemberOf: sequence) } // MARK: - KeyPath where Root: NSManagedObject, Value: QueryableAttributeType & Comparable /** Creates a `Where` clause by comparing if a property is less than a value ``` let person = dataStack.fetchOne(From().where(\.age < 20)) ``` */ public func < (_ keyPath: KeyPath, _ value: V) -> Where { return Where("%K < %@", keyPath._kvcKeyPathString!, value.cs_toQueryableNativeType()) } /** Creates a `Where` clause by comparing if a property is greater than a value ``` let person = dataStack.fetchOne(From().where(\.age > 20)) ``` */ public func > (_ keyPath: KeyPath, _ value: V) -> Where { return Where("%K > %@", keyPath._kvcKeyPathString!, value.cs_toQueryableNativeType()) } /** Creates a `Where` clause by comparing if a property is less than or equal to a value ``` let person = dataStack.fetchOne(From().where(\.age <= 20)) ``` */ public func <= (_ keyPath: KeyPath, _ value: V) -> Where { return Where("%K <= %@", keyPath._kvcKeyPathString!, value.cs_toQueryableNativeType()) } /** Creates a `Where` clause by comparing if a property is greater than or equal to a value ``` let person = dataStack.fetchOne(From().where(\.age >= 20)) ``` */ public func >= (_ keyPath: KeyPath, _ value: V) -> Where { return Where("%K >= %@", keyPath._kvcKeyPathString!, value.cs_toQueryableNativeType()) } // MARK: - KeyPath where Root: NSManagedObject, Value: Optional /** Creates a `Where` clause by comparing if a property is less than a value ``` let person = dataStack.fetchOne(From().where(\.age < 20)) ``` */ public func < (_ keyPath: KeyPath>, _ value: V?) -> Where { if let value = value { return Where("%K < %@", keyPath._kvcKeyPathString!, value.cs_toQueryableNativeType()) } else { return Where("%K < nil", keyPath._kvcKeyPathString!) } } /** Creates a `Where` clause by comparing if a property is greater than a value ``` let person = dataStack.fetchOne(From().where(\.age > 20)) ``` */ public func > (_ keyPath: KeyPath>, _ value: V?) -> Where { if let value = value { return Where("%K > %@", keyPath._kvcKeyPathString!, value.cs_toQueryableNativeType()) } else { return Where("%K > nil", keyPath._kvcKeyPathString!) } } /** Creates a `Where` clause by comparing if a property is less than or equal to a value ``` let person = dataStack.fetchOne(From().where(\.age <= 20)) ``` */ public func <= (_ keyPath: KeyPath>, _ value: V?) -> Where { if let value = value { return Where("%K <= %@", keyPath._kvcKeyPathString!, value.cs_toQueryableNativeType()) } else { return Where("%K <= nil", keyPath._kvcKeyPathString!) } } /** Creates a `Where` clause by comparing if a property is greater than or equal to a value ``` let person = dataStack.fetchOne(From().where(\.age >= 20)) ``` */ public func >= (_ keyPath: KeyPath>, _ value: V?) -> Where { if let value = value { return Where("%K >= %@", keyPath._kvcKeyPathString!, value.cs_toQueryableNativeType()) } else { return Where("%K >= nil", keyPath._kvcKeyPathString!) } } // MARK: - KeyPath where Root: NSManagedObject, Value: NSManagedObject /** 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: D) -> Where { return Where(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: D) -> Where { return !Where(keyPath._kvcKeyPathString!, isEqualTo: object) } /** Creates a `Where` clause by checking if a sequence contains a value of a property ``` let dog = dataStack.fetchOne(From().where([john, bob, joe] ~= \.master)) ``` */ public func ~= (_ sequence: S, _ keyPath: KeyPath) -> Where where S.Iterator.Element == D { return Where(keyPath._kvcKeyPathString!, isMemberOf: sequence) } /** 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, _ objectID: NSManagedObjectID) -> Where { 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 ``` let dog = dataStack.fetchOne(From().where(\.master != john)) ``` */ public func != (_ keyPath: KeyPath, _ objectID: NSManagedObjectID) -> Where { 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 ``` let dog = dataStack.fetchOne(From().where([john, bob, joe] ~= \.master)) ``` */ public func ~= (_ sequence: S, _ keyPath: KeyPath) -> Where where S.Iterator.Element == NSManagedObjectID { return Where(keyPath._kvcKeyPathString!, isMemberOf: sequence) } // MARK: - KeyPath where Root: NSManagedObject, Value: Optional /** 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: D?) -> Where { return Where(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 ``` let dog = dataStack.fetchOne(From().where(\.master != john)) ``` */ public func != (_ keyPath: KeyPath>, _ object: D?) -> Where { return !Where(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 ``` let dog = dataStack.fetchOne(From().where([john, bob, joe] ~= \.master)) ``` */ public func ~= (_ sequence: S, _ keyPath: KeyPath>) -> Where where S.Iterator.Element == D { return Where(keyPath._kvcKeyPathString!, isMemberOf: sequence) } /** 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>, _ objectID: NSManagedObjectID) -> Where { 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>, _ objectID: NSManagedObjectID) -> Where { return !Where(keyPath._kvcKeyPathString!, isEqualTo: objectID) } /** Creates a `Where` clause by checking if a sequence contains a value of a property ``` let dog = dataStack.fetchOne(From().where([john, bob, joe] ~= \.master)) ``` */ public func ~= (_ sequence: S, _ keyPath: KeyPath>) -> Where where S.Iterator.Element == NSManagedObjectID { return Where(keyPath._kvcKeyPathString!, isMemberOf: sequence) } // MARK: - KeyPath where Root: CoreStoreObject, Value: FieldContainer.Stored /** Creates a `Where` clause by comparing if a property is equal to a value ``` let person = dataStack.fetchOne(From().where(\.$nickname == "John")) ``` */ public func == (_ keyPath: KeyPath.Stored>, _ value: V) -> Where { return Where(keyPath, isEqualTo: value) } /** Creates a `Where` clause by comparing if a property is not equal to a value ``` let person = dataStack.fetchOne(From().where(\.$nickname != "John")) ``` */ public func != (_ keyPath: KeyPath.Stored>, _ value: V) -> Where { return !Where(keyPath, isEqualTo: value) } /** Creates a `Where` clause by checking if a sequence contains the value of a property ``` let dog = dataStack.fetchOne(From().where(["Pluto", "Snoopy", "Scooby"] ~= \.nickname)) ``` */ public func ~= (_ sequence: S, _ keyPath: KeyPath.Stored>) -> Where where S.Iterator.Element == V { return Where(O.meta[keyPath: keyPath].keyPath, isMemberOf: sequence) } // MARK: - KeyPath where Root: CoreStoreObject, Value: FieldContainer.Stored /** Creates a `Where` clause by comparing if a property is less than a value ``` let person = dataStack.fetchOne(From().where(\.$age < 20)) ``` */ public func < (_ keyPath: KeyPath.Stored>, _ value: V) -> Where { return Where("%K < %@", O.meta[keyPath: keyPath].keyPath, value.cs_toFieldStoredNativeType() as! V.FieldStoredNativeType) } /** Creates a `Where` clause by comparing if a property is less than a value ``` let person = dataStack.fetchOne(From().where(\.$age < 20)) ``` */ public func < (_ keyPath: KeyPath.Stored>, _ value: V) -> Where where V.Wrapped: Comparable { return Where("%K < %@", O.meta[keyPath: keyPath].keyPath, value.cs_toFieldStoredNativeType() as! V.FieldStoredNativeType) } /** Creates a `Where` clause by comparing if a property is greater than a value ``` let person = dataStack.fetchOne(From().where(\.$age > 20)) ``` */ public func > (_ keyPath: KeyPath.Stored>, _ value: V) -> Where { return Where("%K > %@", O.meta[keyPath: keyPath].keyPath, value.cs_toFieldStoredNativeType() as! V.FieldStoredNativeType) } /** Creates a `Where` clause by comparing if a property is greater than a value ``` let person = dataStack.fetchOne(From().where(\.$age > 20)) ``` */ public func > (_ keyPath: KeyPath.Stored>, _ value: V) -> Where where V.Wrapped: Comparable { return Where("%K > %@", O.meta[keyPath: keyPath].keyPath, value.cs_toFieldStoredNativeType() as! V.FieldStoredNativeType) } /** Creates a `Where` clause by comparing if a property is less than or equal to a value ``` let person = dataStack.fetchOne(From().where(\.$age <= 20)) ``` */ public func <= (_ keyPath: KeyPath.Stored>, _ value: V) -> Where { return Where("%K <= %@", O.meta[keyPath: keyPath].keyPath, value.cs_toFieldStoredNativeType() as! V.FieldStoredNativeType) } /** Creates a `Where` clause by comparing if a property is less than or equal to a value ``` let person = dataStack.fetchOne(From().where(\.$age <= 20)) ``` */ public func <= (_ keyPath: KeyPath.Stored>, _ value: V) -> Where where V.Wrapped: Comparable { return Where("%K <= %@", O.meta[keyPath: keyPath].keyPath, value.cs_toFieldStoredNativeType() as! V.FieldStoredNativeType) } /** Creates a `Where` clause by comparing if a property is greater than or equal to a value ``` let person = dataStack.fetchOne(From().where(\.$age >= 20)) ``` */ public func >= (_ keyPath: KeyPath.Stored>, _ value: V) -> Where { return Where("%K >= %@", O.meta[keyPath: keyPath].keyPath, value.cs_toFieldStoredNativeType() as! V.FieldStoredNativeType) } /** Creates a `Where` clause by comparing if a property is greater than or equal to a value ``` let person = dataStack.fetchOne(From().where(\.$age >= 20)) ``` */ public func >= (_ keyPath: KeyPath.Stored>, _ value: V) -> Where where V.Wrapped: Comparable { return Where("%K >= %@", O.meta[keyPath: keyPath].keyPath, value.cs_toFieldStoredNativeType() as! V.FieldStoredNativeType) } // MARK: - KeyPath where Root: CoreStoreObject, Value: FieldContainer.Relationship /** 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: D.DestinationObjectType?) -> Where { 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 = 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 ``` let dog = dataStack.fetchOne(From().where(\.$master != john)) ``` */ public func != (_ keyPath: KeyPath.Relationship>, _ object: D.DestinationObjectType?) -> Where { 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 = 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 checking if a sequence contains a value of a property ``` let dog = dataStack.fetchOne(From().where([john, bob, joe] ~= \.$master)) ``` */ public func ~= (_ sequence: S, _ keyPath: KeyPath.Relationship>) -> Where where S.Iterator.Element == D.DestinationObjectType { return Where(O.meta[keyPath: keyPath].keyPath, isMemberOf: sequence) } // MARK: - KeyPath where Root: CoreStoreObject, Value: ValueContainer.Required /** Creates a `Where` clause by comparing if a property is equal to a value ``` let person = dataStack.fetchOne(From().where(\.nickname == "John")) ``` */ public func == (_ keyPath: KeyPath.Required>, _ value: V) -> Where { 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 = dataStack.fetchOne(From().where(\.nickname != "John")) ``` */ public func != (_ keyPath: KeyPath.Required>, _ value: V) -> Where { return !Where(O.meta[keyPath: keyPath].keyPath, isEqualTo: value) } /** Creates a `Where` clause by checking if a sequence contains the value of a property ``` let dog = dataStack.fetchOne(From().where(["Pluto", "Snoopy", "Scooby"] ~= \.nickname)) ``` */ public func ~= (_ sequence: S, _ keyPath: KeyPath.Required>) -> Where where S.Iterator.Element == V { return Where(O.meta[keyPath: keyPath].keyPath, isMemberOf: sequence) } // MARK: - KeyPath where Root: CoreStoreObject, Value: ValueContainer.Optional /** Creates a `Where` clause by comparing if a property is equal to a value ``` let person = dataStack.fetchOne(From().where(\.nickname == "John")) ``` */ public func == (_ keyPath: KeyPath.Optional>, _ value: V?) -> Where { 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 = dataStack.fetchOne(From().where(\.nickname != "John")) ``` */ public func != (_ keyPath: KeyPath.Optional>, _ value: V?) -> Where { return !Where(O.meta[keyPath: keyPath].keyPath, isEqualTo: value) } /** Creates a `Where` clause by checking if a sequence contains the value of a property ``` let dog = dataStack.fetchOne(From().where(["Pluto", "Snoopy", "Scooby"] ~= \.nickname)) ``` */ public func ~= (_ sequence: S, _ keyPath: KeyPath.Optional>) -> Where where S.Iterator.Element == V { return Where(O.meta[keyPath: keyPath].keyPath, isMemberOf: sequence) } // MARK: - KeyPath where Root: CoreStoreObject, Value: ValueContainer.Required /** Creates a `Where` clause by comparing if a property is less than a value ``` let person = dataStack.fetchOne(From().where(\.age < 20)) ``` */ public func < (_ keyPath: KeyPath.Required>, _ value: V) -> Where { return Where("%K < %@", O.meta[keyPath: keyPath].keyPath, value.cs_toQueryableNativeType()) } /** Creates a `Where` clause by comparing if a property is greater than a value ``` let person = dataStack.fetchOne(From().where(\.age > 20)) ``` */ public func > (_ keyPath: KeyPath.Required>, _ value: V) -> Where { return Where("%K > %@", O.meta[keyPath: keyPath].keyPath, value.cs_toQueryableNativeType()) } /** Creates a `Where` clause by comparing if a property is less than or equal to a value ``` let person = dataStack.fetchOne(From().where(\.age <= 20)) ``` */ public func <= (_ keyPath: KeyPath.Required>, _ value: V) -> Where { return Where("%K <= %@", O.meta[keyPath: keyPath].keyPath, value.cs_toQueryableNativeType()) } /** Creates a `Where` clause by comparing if a property is greater than or equal to a value ``` let person = dataStack.fetchOne(From().where(\.age >= 20)) ``` */ public func >= (_ keyPath: KeyPath.Required>, _ value: V) -> Where { return Where("%K >= %@", O.meta[keyPath: keyPath].keyPath, value.cs_toQueryableNativeType()) } // MARK: - KeyPath where Root: CoreStoreObject, Value: ValueContainer.Optional /** Creates a `Where` clause by comparing if a property is less than a value ``` let person = dataStack.fetchOne(From().where(\.age < 20)) ``` */ public func < (_ keyPath: KeyPath.Optional>, _ value: V?) -> Where { if let value = value { return Where("%K < %@", O.meta[keyPath: keyPath].keyPath, value.cs_toQueryableNativeType()) } else { return Where("%K < nil", O.meta[keyPath: keyPath].keyPath) } } /** Creates a `Where` clause by comparing if a property is greater than a value ``` let person = dataStack.fetchOne(From().where(\.age > 20)) ``` */ public func > (_ keyPath: KeyPath.Optional>, _ value: V?) -> Where { if let value = value { return Where("%K > %@", O.meta[keyPath: keyPath].keyPath, value.cs_toQueryableNativeType()) } else { 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 ``` let person = dataStack.fetchOne(From().where(\.age <= 20)) ``` */ public func <= (_ keyPath: KeyPath.Optional>, _ value: V?) -> Where { if let value = value { return Where("%K <= %@", O.meta[keyPath: keyPath].keyPath, value.cs_toQueryableNativeType()) } else { 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 ``` let person = dataStack.fetchOne(From().where(\.age >= 20)) ``` */ public func >= (_ keyPath: KeyPath.Optional>, _ value: V?) -> Where { if let value = value { return Where("%K >= %@", O.meta[keyPath: keyPath].keyPath, value.cs_toQueryableNativeType()) } else { return Where("%K >= nil", O.meta[keyPath: keyPath].keyPath) } } // MARK: - KeyPath where Root: CoreStoreObject, Value: RelationshipContainer.ToOne /** 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.ToOne>, _ object: D) -> Where { 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 = dataStack.fetchOne(From().where(\.master == john)) ``` */ public func == (_ keyPath: KeyPath.ToOne>, _ object: D?) -> Where { 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 = dataStack.fetchOne(From().where(\.master != john)) ``` */ public func != (_ keyPath: KeyPath.ToOne>, _ object: D) -> Where { 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 = dataStack.fetchOne(From().where(\.master != john)) ``` */ public func != (_ keyPath: KeyPath.ToOne>, _ object: D?) -> Where { return !Where(O.meta[keyPath: keyPath].keyPath, isEqualTo: object) } /** Creates a `Where` clause by checking if a sequence contains a value of a property ``` let dog = dataStack.fetchOne(From().where([john, bob, joe] ~= \.master)) ``` */ public func ~= (_ sequence: S, _ keyPath: KeyPath.ToOne>) -> Where where S.Iterator.Element == D { return Where(O.meta[keyPath: keyPath].keyPath, isMemberOf: sequence) }