mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-31 06:33:06 +02:00
add Where comparison operators for optional values
This commit is contained in:
@@ -276,6 +276,82 @@ public extension ValueContainer.Optional {
|
|||||||
return !Where(attribute.keyPath, isEqualTo: value)
|
return !Where(attribute.keyPath, isEqualTo: value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Creates a `Where` clause from a `CoreStoreObject.Value` property.
|
||||||
|
```
|
||||||
|
let person = CoreStore.fetchOne(From<Person>(), Person.where { $0.age < 20 })
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
@inline(__always)
|
||||||
|
public static func < (_ attribute: ValueContainer<O>.Optional<V>, _ 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>(), Person.where { $0.age > 20 })
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
@inline(__always)
|
||||||
|
public static func > (_ attribute: ValueContainer<O>.Optional<V>, _ 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>(), Person.where { $0.age <= 20 })
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
@inline(__always)
|
||||||
|
public static func <= (_ attribute: ValueContainer<O>.Optional<V>, _ 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>(), Person.where { $0.age >= 20 })
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
@inline(__always)
|
||||||
|
public static func >= (_ attribute: ValueContainer<O>.Optional<V>, _ 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.
|
Creates a `Where` clause from a `CoreStoreObject.Value` property.
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user