mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-15 13:43:43 +01:00
add query overloads to == so comparison with nil don't confuse the compiler
This commit is contained in:
@@ -76,6 +76,17 @@ public func == <O: NSManagedObject, V: QueryableAttributeType & Equatable>(_ key
|
||||
return Where<O>(keyPath._kvcKeyPathString!, isEqualTo: value)
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.nickname == nil))
|
||||
```
|
||||
*/
|
||||
public func == <O: NSManagedObject, V: QueryableAttributeType & Equatable>(_ keyPath: KeyPath<O, Optional<V>>, _ null: Void?) -> Where<O> {
|
||||
|
||||
return Where<O>("%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 != <O: NSManagedObject, V: QueryableAttributeType & Equatable>(_ key
|
||||
return !Where<O>(keyPath._kvcKeyPathString!, isEqualTo: value)
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is not equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.nickname != nil))
|
||||
```
|
||||
*/
|
||||
public func != <O: NSManagedObject, V: QueryableAttributeType & Equatable>(_ keyPath: KeyPath<O, Optional<V>>, _ null: Void?) -> Where<O> {
|
||||
|
||||
return Where<O>("%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 < <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ key
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is less than a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.age < 20))
|
||||
```
|
||||
*/
|
||||
public func < <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ keyPath: KeyPath<O, Optional<V>>, _ null: Void?) -> Where<O> {
|
||||
|
||||
return Where<O>("%K < nil", keyPath._kvcKeyPathString!)
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is greater than a value
|
||||
```
|
||||
@@ -184,6 +217,17 @@ public func > <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ key
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is greater than a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.age > nil))
|
||||
```
|
||||
*/
|
||||
public func > <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ keyPath: KeyPath<O, Optional<V>>, _ null: Void?) -> Where<O> {
|
||||
|
||||
return Where<O>("%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 <= <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ ke
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is less than or equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.age <= nil))
|
||||
```
|
||||
*/
|
||||
public func <= <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ keyPath: KeyPath<O, Optional<V>>, _ null: Void?) -> Where<O> {
|
||||
|
||||
return Where<O>("%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 >= <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ ke
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is greater than or equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.age >= nil))
|
||||
```
|
||||
*/
|
||||
public func >= <O: NSManagedObject, V: QueryableAttributeType & Comparable>(_ keyPath: KeyPath<O, Optional<V>>, _ null: Void?) -> Where<O> {
|
||||
|
||||
return Where<O>("%K >= nil", keyPath._kvcKeyPathString!)
|
||||
}
|
||||
|
||||
|
||||
// MARK: - KeyPath where Root: NSManagedObject, Value: NSManagedObject
|
||||
|
||||
@@ -303,6 +369,17 @@ public func == <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, Op
|
||||
return Where<O>(keyPath._kvcKeyPathString!, isEqualTo: object)
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is equal to a value
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where(\.master == nil))
|
||||
```
|
||||
*/
|
||||
public func == <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, Optional<D>>, _ null: Void?) -> Where<O> {
|
||||
|
||||
return Where<O>("%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 != <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, Op
|
||||
return !Where<O>(keyPath._kvcKeyPathString!, isEqualTo: object)
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is not equal to a value
|
||||
```
|
||||
let dog = CoreStore.fetchOne(From<Dog>().where(\.master != nil))
|
||||
```
|
||||
*/
|
||||
public func != <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, Optional<D>>, _ null: Void?) -> Where<O> {
|
||||
|
||||
return Where<O>("%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 == <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>, _ va
|
||||
return Where<O>(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<Person>().where(\.nickname == nil))
|
||||
```
|
||||
*/
|
||||
public func == <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>, _ null: Void?) -> Where<O> {
|
||||
|
||||
return Where<O>("%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 != <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>, _ va
|
||||
return !Where<O>(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<Person>().where(\.nickname != nil))
|
||||
```
|
||||
*/
|
||||
public func != <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>, _ null: Void?) -> Where<O> {
|
||||
|
||||
return Where<O>("%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 < <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>, _ val
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is less than a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.age < nil))
|
||||
```
|
||||
*/
|
||||
public func < <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>, _ null: Void?) -> Where<O> {
|
||||
|
||||
return Where<O>("%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 > <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>, _ val
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is greater than a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.age > nil))
|
||||
```
|
||||
*/
|
||||
public func > <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>, _ null: Void?) -> Where<O> {
|
||||
|
||||
return Where<O>("%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 <= <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>, _ va
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is less than or equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.age <= nil))
|
||||
```
|
||||
*/
|
||||
public func <= <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>, _ null: Void?) -> Where<O> {
|
||||
|
||||
return Where<O>("%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 >= <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>, _ va
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a `Where` clause by comparing if a property is greater than or equal to a value
|
||||
```
|
||||
let person = CoreStore.fetchOne(From<Person>().where(\.age >= nil))
|
||||
```
|
||||
*/
|
||||
public func >= <O, V>(_ keyPath: KeyPath<O, ValueContainer<O>.Optional<V>>, _ null: Void?) -> Where<O> {
|
||||
|
||||
return Where<O>("%K >= nil", O.meta[keyPath: keyPath].keyPath)
|
||||
}
|
||||
|
||||
|
||||
// MARK: - KeyPath where Root: CoreStoreObject, Value: RelationshipContainer<Root>.ToOne<CoreStoreObject>
|
||||
|
||||
@@ -577,6 +731,17 @@ public func == <O, D>(_ keyPath: KeyPath<O, RelationshipContainer<O>.ToOne<D>>,
|
||||
return Where<O>(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<Dog>().where(\.master == nil))
|
||||
```
|
||||
*/
|
||||
public func == <O, D>(_ keyPath: KeyPath<O, RelationshipContainer<O>.ToOne<D>>, _ null: Void?) -> Where<O> {
|
||||
|
||||
return Where<O>("%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 != <O, D>(_ keyPath: KeyPath<O, RelationshipContainer<O>.ToOne<D>>,
|
||||
return !Where<O>(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<Dog>().where(\.master != nil))
|
||||
```
|
||||
*/
|
||||
public func != <O, D>(_ keyPath: KeyPath<O, RelationshipContainer<O>.ToOne<D>>, _ null: Void?) -> Where<O> {
|
||||
|
||||
return Where<O>("%K != nil", O.meta[keyPath: keyPath].keyPath)
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a `Where` clause by checking if a sequence contains a value of a property
|
||||
```
|
||||
|
||||
@@ -158,9 +158,9 @@ public struct Where<D: DynamicObject>: 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<V: QueryableAttributeType>(_ keyPath: KeyPath<D, V>, isEqualTo value: Void?) {
|
||||
public init<V: QueryableAttributeType>(_ keyPath: KeyPath<D, V>, 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<O: DynamicObject>(_ keyPath: KeyPath<D, O>, isEqualTo value: Void?) {
|
||||
public init<O: DynamicObject>(_ keyPath: KeyPath<D, O>, 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<V>(_ keyPath: KeyPath<D, ValueContainer<D>.Optional<V>>, isEqualTo value: Void?) {
|
||||
public init<V>(_ keyPath: KeyPath<D, ValueContainer<D>.Optional<V>>, 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<O>(_ keyPath: KeyPath<D, RelationshipContainer<D>.ToOne<O>>, isEqualTo value: Void?) {
|
||||
public init<O>(_ keyPath: KeyPath<D, RelationshipContainer<D>.ToOne<O>>, isEqualTo null: Void?) {
|
||||
|
||||
self.init(D.meta[keyPath: keyPath].keyPath, isEqualTo: value)
|
||||
self.init(D.meta[keyPath: keyPath].keyPath, isEqualTo: null)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user