From 99b871b97a6c2bb10128449e5dd23176cef2b671 Mon Sep 17 00:00:00 2001 From: John Estropia Date: Wed, 20 Feb 2019 18:47:29 +0900 Subject: [PATCH] add missing documentations for Where.Expression, updated playgrounds --- Playground_iOS.playground/Contents.swift | 70 +++-- Playground_macOS.playground/Contents.swift | 72 +++-- Sources/Where.Expression.swift | 342 +++++++++++++++++++-- Sources/WhereClauseType.swift | 2 +- 4 files changed, 409 insertions(+), 77 deletions(-) diff --git a/Playground_iOS.playground/Contents.swift b/Playground_iOS.playground/Contents.swift index af63d92..32e5d00 100644 --- a/Playground_iOS.playground/Contents.swift +++ b/Playground_iOS.playground/Contents.swift @@ -1,5 +1,8 @@ import UIKit import CoreStore +import PlaygroundSupport + +PlaygroundPage.current.needsIndefiniteExecution = true /// Model Declaration ===== class Animal: CoreStoreObject { @@ -24,30 +27,53 @@ let dataStack = DataStack( ] ) ) -try dataStack.addStorageAndWait(SQLiteStore(fileName: "data.sqlite")) -/// ======================= +dataStack.addStorage( + SQLiteStore(fileName: "data.sqlite"), + completion: { result in -/// Transactions ========== -dataStack.perform(synchronous: { transaction in + switch result { - let animal = transaction.create(Into()) - animal.species .= "Sparrow" - animal.color .= .yellow + case .failure(let error): + print(error) - let person = transaction.create(Into()) - person.name .= "John" - person.pets.value.insert(animal) -}) -/// ======================= + case .success: + /// Transactions ========== + dataStack.perform( + asynchronous: { transaction in + + let animal = transaction.create(Into()) + animal.species .= "Sparrow" + animal.color .= .yellow + + let person = transaction.create(Into()) + person.name .= "John" + person.pets.value.insert(animal) + }, + completion: { result in + + switch result { + + case .failure(let error): + print(error) + + case .success: + /// Accessing Objects ===== + let bird = try! dataStack.fetchOne(From().where(\.species == "Sparrow"))! + print(bird.species.value) + print(bird.color.value as Any) + print(bird) + + let owner = bird.master.value! + print(owner.name.value as Any) + print(owner.pets.count) + print(owner) + /// ======================= + } + } + ) + /// ======================= + } + } +) -/// Accessing Objects ===== -let bird = dataStack.fetchOne(From().where(\.species == "Sparrow"))! -print(bird.species.value) -print(bird.color.value as Any) -print(bird) -let owner = bird.master.value! -print(owner.name.value) -print(owner.pets.count as Any) -print(owner) -/// ======================= diff --git a/Playground_macOS.playground/Contents.swift b/Playground_macOS.playground/Contents.swift index 2caabe0..e01652e 100644 --- a/Playground_macOS.playground/Contents.swift +++ b/Playground_macOS.playground/Contents.swift @@ -1,5 +1,8 @@ import AppKit import CoreStore +import PlaygroundSupport + +PlaygroundPage.current.needsIndefiniteExecution = true /// Model Declaration ===== class Animal: CoreStoreObject { @@ -24,32 +27,51 @@ let dataStack = DataStack( ] ) ) -try dataStack.addStorageAndWait(SQLiteStore(fileName: "data.sqlite")) -/// ======================= +dataStack.addStorage( + SQLiteStore(fileName: "data.sqlite"), + completion: { result in -/// Transactions ========== -try dataStack.perform( - synchronous: { transaction in + switch result { - let animal = transaction.create(Into()) - animal.species .= "Sparrow" - animal.color .= .yellow + case .failure(let error): + print(error) - let person = transaction.create(Into()) - person.name .= "John" - person.pets.value.insert(animal) -} + case .success: + /// Transactions ========== + dataStack.perform( + asynchronous: { transaction in + + let animal = transaction.create(Into()) + animal.species .= "Sparrow" + animal.color .= .yellow + + let person = transaction.create(Into()) + person.name .= "John" + person.pets.value.insert(animal) + }, + completion: { result in + + switch result { + + case .failure(let error): + print(error) + + case .success: + /// Accessing Objects ===== + let bird = try! dataStack.fetchOne(From().where(\.species == "Sparrow"))! + print(bird.species.value) + print(bird.color.value as Any) + print(bird) + + let owner = bird.master.value! + print(owner.name.value as Any) + print(owner.pets.count) + print(owner) + /// ======================= + } + } + ) + /// ======================= + } + } ) -/// ======================= - -/// Accessing Objects ===== -let bird = try dataStack.fetchOne(From().where(\.species == "Sparrow"))! -print(bird.species.value) -print(bird.color.value as Any) -print(bird) - -let owner = bird.master.value! -print(owner.name.value as Any) -print(owner.pets.count) -print(owner) -/// ======================= diff --git a/Sources/Where.Expression.swift b/Sources/Where.Expression.swift index 11c4fd1..bc1808b 100644 --- a/Sources/Where.Expression.swift +++ b/Sources/Where.Expression.swift @@ -29,11 +29,24 @@ import CoreData // MARK: - ~ +/** + Connects multiple `DynamicKeyPath`s to create a type-safe chain usable in query/fetch expressions +``` +let owner = CoreStore.fetchOne( + From().where( + (\.master ~ \.name) == "John" + ) +) +``` + */ infix operator ~ : AdditionPrecedence // MARK: - WhereExpressionTrait +/** + Used only for `Where.Expression` type constraints. Currently supports `SingleTarget` and `CollectionTarget`. + */ public protocol WhereExpressionTrait {} @@ -43,8 +56,20 @@ extension Where { // MARK: - Expression + /** + Type-safe keyPath chain usable in query/fetch expressions. + ``` + let expression: Where.Expression = (\.master ~ \.name) + let owner = CoreStore.fetchOne( + From().where(expression == "John") + ) + ``` + */ public struct Expression: CustomStringConvertible, DynamicKeyPath { + /** + Currently supports `SingleTarget` and `CollectionTarget`. + */ public typealias Trait = T @@ -83,10 +108,17 @@ extension Where { // MARK: - SingleTarget + /** + Used only for `Where.Expression` type constraints. Specifies that this `Where.Expression` type pertains to an attribute property expression. + */ public enum SingleTarget: WhereExpressionTrait {} + // MARK: - CollectionTarget + /** + Used only for `Where.Expression` type constraints. Specifies that this `Where.Expression` type pertains to a to-many relationship expression. + */ public enum CollectionTarget: WhereExpressionTrait {} } @@ -95,47 +127,101 @@ extension Where { // MARK: ~ where D: NSManagedObject +/** + Connects multiple `DynamicKeyPath`s to create a type-safe chain usable in query/fetch expressions + ``` + let owner = CoreStore.fetchOne(From().where((\.master ~ \.name) == "John")) + ``` + */ public func ~(_ lhs: KeyPath, _ rhs: KeyPath) -> Where.Expression.SingleTarget, V> { return .init(lhs.cs_keyPathString, rhs.cs_keyPathString) } -public func ~(_ lhs: KeyPath, _ rhs: KeyPath) -> Where.Expression.SingleTarget, V> { +/** + Connects multiple `DynamicKeyPath`s to create a type-safe chain usable in query/fetch expressions + ``` + let owner = CoreStore.fetchOne(From().where((\.master ~ \.name) == "John")) + ``` + */ +public func ~ (_ lhs: KeyPath, _ rhs: KeyPath) -> Where.Expression.SingleTarget, V> { return .init(lhs.cs_keyPathString, rhs.cs_keyPathString) } -public func ~(_ lhs: KeyPath, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, V> { +/** + Connects multiple `DynamicKeyPath`s to create a type-safe chain usable in query/fetch expressions + ``` + let happyPets = CoreStore.fetchAll(From().where((\.master ~ \.pets).count() > 1)) + ``` + */ +public func ~ (_ lhs: KeyPath, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, V> { return .init(lhs.cs_keyPathString, rhs.cs_keyPathString) } -public func ~(_ lhs: KeyPath, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, V> { +/** + Connects multiple `DynamicKeyPath`s to create a type-safe chain usable in query/fetch expressions + ``` + let happyPets = CoreStore.fetchAll(From().where((\.master ~ \.pets).count() > 1)) + ``` + */ +public func ~ (_ lhs: KeyPath, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, V> { return .init(lhs.cs_keyPathString, rhs.cs_keyPathString) } -public func ~(_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression { +/** + Connects multiple `DynamicKeyPath`s to create a type-safe chain usable in query/fetch expressions + ``` + let johnsSonInLaw = CoreStore.fetchOne(From().where((\.spouse ~ \.father ~ \.name) == "John")) + ``` + */ +public func ~ (_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression { return .init(lhs.cs_keyPathString, rhs.cs_keyPathString) } -public func ~(_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, V> { +/** + Connects multiple `DynamicKeyPath`s to create a type-safe chain usable in query/fetch expressions + ``` + let johnsSonInLaw = CoreStore.fetchOne(From().where((\.spouse ~ \.father ~ \.name) == "John")) + ``` + */ +public func ~ (_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression { return .init(lhs.cs_keyPathString, rhs.cs_keyPathString) } -public func ~(_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression { +/** + Connects multiple `DynamicKeyPath`s to create a type-safe chain usable in query/fetch expressions + ``` + let spouseHasSiblings = CoreStore.fetchOne(From().where((\.spouse ~ \.father ~ \.children).count() > 0)) + ``` + */ +public func ~ (_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, V> { return .init(lhs.cs_keyPathString, rhs.cs_keyPathString) } -public func ~(_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, V> { +/** + Connects multiple `DynamicKeyPath`s to create a type-safe chain usable in query/fetch expressions + ``` + let spouseHasSiblings = CoreStore.fetchOne(From().where((\.spouse ~ \.father ~ \.children).count() > 0)) + ``` + */ +public func ~ (_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, V> { return .init(lhs.cs_keyPathString, rhs.cs_keyPathString) } -public func ~(_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, V> { +/** + Connects multiple `DynamicKeyPath`s to create a type-safe chain usable in query/fetch expressions + ``` + let spousesWithBadNamingSense = CoreStore.fetchAll(From().where((\.spouse ~ \.pets ~ \.name).any() == "Spot")) + ``` + */ +public func ~ (_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, V> { return .init(lhs.cs_keyPathString, rhs.cs_keyPathString) } @@ -143,7 +229,13 @@ public func ~(_ lhs: KeyPath.ToOne>, _ rhs: KeyPath) -> Where.Expression.SingleTarget, K.ValueType> where K.ObjectType == O { +/** + Connects multiple `DynamicKeyPath`s to create a type-safe chain usable in query/fetch expressions + ``` + let owner = CoreStore.fetchOne(From().where((\.master ~ \.name) == "John")) + ``` + */ +public func ~ (_ lhs: KeyPath.ToOne>, _ rhs: KeyPath) -> Where.Expression.SingleTarget, K.ValueType> where K.ObjectType == O { return .init( D.meta[keyPath: lhs].cs_keyPathString, @@ -151,7 +243,41 @@ public func ~(_ lhs: KeyPath.ToOne>, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, K.ValueType> where K.ObjectType == O { +/** + Connects multiple `DynamicKeyPath`s to create a type-safe chain usable in query/fetch expressions + ``` + let owner = CoreStore.fetchOne(From().where((\.master ~ \.name) == "John")) + ``` + */ +public func ~ (_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression where K.ObjectType == O { + + return .init( + lhs.cs_keyPathString, + O.meta[keyPath: rhs].cs_keyPathString + ) +} + +/** + Connects multiple `DynamicKeyPath`s to create a type-safe chain usable in query/fetch expressions + ``` + let owner = CoreStore.fetchOne(From().where((\.master ~ \.name) == "John")) + ``` + */ +public func ~ (_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression where K.ObjectType == O { + + return .init( + lhs.cs_keyPathString, + O.meta[keyPath: rhs].cs_keyPathString + ) +} + +/** + Connects multiple `DynamicKeyPath`s to create a type-safe chain usable in query/fetch expressions + ``` + let happyPets = CoreStore.fetchAll(From().where((\.master ~ \.pets).count() > 1)) + ``` + */ +public func ~ (_ lhs: KeyPath.ToOne>, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, K.ValueType> where K.ObjectType == O { return .init( D.meta[keyPath: lhs].cs_keyPathString, @@ -159,7 +285,13 @@ public func ~(_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression where K.ObjectType == O { +/** + Connects multiple `DynamicKeyPath`s to create a type-safe chain usable in query/fetch expressions + ``` + let happyPets = CoreStore.fetchAll(From().where((\.master ~ \.pets).count() > 1)) + ``` + */ +public func ~ (_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, K.ValueType> where K.ObjectType == O { return .init( lhs.cs_keyPathString, @@ -167,7 +299,13 @@ public func ~(_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, K.ValueType> where K.ObjectType == O { +/** + Connects multiple `DynamicKeyPath`s to create a type-safe chain usable in query/fetch expressions + ``` + let happyPets = CoreStore.fetchAll(From().where((\.master ~ \.pets).count() > 1)) + ``` + */ +public func ~ (_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, K.ValueType> where K.ObjectType == O { return .init( lhs.cs_keyPathString, @@ -175,23 +313,13 @@ public func ~(_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression where K.ObjectType == O { - - return .init( - lhs.cs_keyPathString, - O.meta[keyPath: rhs].cs_keyPathString - ) -} - -public func ~(_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, K.ValueType> where K.ObjectType == O { - - return .init( - lhs.cs_keyPathString, - O.meta[keyPath: rhs].cs_keyPathString - ) -} - -public func ~(_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, KV.ValueType> where KC.ObjectType == D, KV.ObjectType == O { +/** + Connects multiple `DynamicKeyPath`s to create a type-safe chain usable in query/fetch expressions + ``` + let spousesWithBadNamingSense = CoreStore.fetchAll(From().where((\.master ~ \.pets ~ \.name).any() == "Spot")) + ``` + */ +public func ~ (_ lhs: Where.Expression, _ rhs: KeyPath) -> Where.Expression.CollectionTarget, KV.ValueType> where KC.ObjectType == D, KV.ObjectType == O { return .init( lhs.cs_keyPathString, @@ -202,16 +330,34 @@ public func ~().where((\.master ~ \.name) == "John")) + ``` + */ public func == (_ lhs: Where.Expression, _ rhs: V) -> Where { return Where(lhs.cs_keyPathString, isEqualTo: rhs) } +/** + Creates a `Where` clause by comparing if an expression is not equal to a value + ``` + let dog = CoreStore.fetchOne(From().where((\.master ~ \.name) != "John")) + ``` + */ public func != (_ lhs: Where.Expression, _ rhs: V) -> Where { return !Where(lhs.cs_keyPathString, isEqualTo: rhs) } +/** + Creates a `Where` clause by checking if a sequence contains a value + ``` + let dog = CoreStore.fetchOne(From().where(["John", "Joe"] ~= (\.master ~ \.name)) + ``` + */ public func ~= (_ sequence: S, _ expression: Where.Expression) -> Where where S.Iterator.Element == V { return Where(expression.cs_keyPathString, isMemberOf: sequence) @@ -220,21 +366,45 @@ public func ~= (_ sequence: S, _ e // MARK: - Where.Expression where V: QueryableAttributeType & Comparable +/** + Creates a `Where` clause by comparing if an expression is less than a value + ``` + let lonelyDog = CoreStore.fetchOne(From().where((\.master ~ \.pets).count() < 2)) + ``` + */ public func < (_ lhs: Where.Expression, _ rhs: V) -> Where { return Where(expression: lhs, function: "<", operand: rhs) } +/** + Creates a `Where` clause by comparing if an expression is less than or equal to a value + ``` + let lonelyDog = CoreStore.fetchOne(From().where((\.master ~ \.pets).count() <= 1) + ``` + */ public func <= (_ lhs: Where.Expression, _ rhs: V) -> Where { return Where(expression: lhs, function: "<=", operand: rhs) } +/** + Creates a `Where` clause by comparing if an expression is greater than a value + ``` + let happyDog = CoreStore.fetchOne(From().where((\.master ~ \.pets).count() > 1) + ``` + */ public func > (_ lhs: Where.Expression, _ rhs: V) -> Where { return Where(expression: lhs, function: ">", operand: rhs) } +/** + Creates a `Where` clause by comparing if an expression is greater than or equal to a value + ``` + let happyDog = CoreStore.fetchOne(From().where((\.master ~ \.pets).count() >= 2) + ``` + */ public func >= (_ lhs: Where.Expression, _ rhs: V) -> Where { return Where(expression: lhs, function: ">=", operand: rhs) @@ -243,26 +413,56 @@ public func >= (_ lhs: Where.Ex // MARK: - Where.Expression where V: Optional +/** + Creates a `Where` clause by comparing if an expression is equal to a value + ``` + let dog = CoreStore.fetchOne(From().where((\.master ~ \.name) == "John")) + ``` + */ public func == (_ lhs: Where.Expression, _ rhs: V) -> Where { return Where(lhs.cs_keyPathString, isEqualTo: rhs) } +/** + Creates a `Where` clause by comparing if an expression is equal to a value + ``` + let dog = CoreStore.fetchOne(From().where((\.master ~ \.name) == "John")) + ``` + */ public func == (_ lhs: Where.Expression, _ rhs: V?) -> Where { return Where(lhs.cs_keyPathString, isEqualTo: rhs) } +/** + Creates a `Where` clause by comparing if an expression is equal to a value + ``` + let dog = CoreStore.fetchOne(From().where((\.master ~ \.name) != "John")) + ``` + */ public func != (_ lhs: Where.Expression, _ rhs: V) -> Where { return !Where(lhs.cs_keyPathString, isEqualTo: rhs) } +/** + Creates a `Where` clause by comparing if an expression is equal to a value + ``` + let dog = CoreStore.fetchOne(From().where((\.master ~ \.name) != "John")) + ``` + */ public func != (_ lhs: Where.Expression, _ rhs: V?) -> Where { return !Where(lhs.cs_keyPathString, isEqualTo: rhs) } +/** + Creates a `Where` clause by checking if a sequence contains a value + ``` + let dog = CoreStore.fetchOne(From().where(["John", "Joe"] ~= (\.master ~ \.name)) + ``` + */ public func ~= (_ sequence: S, _ expression: Where.Expression) -> Where where S.Iterator.Element == V { return Where(expression.cs_keyPathString, isMemberOf: sequence) @@ -271,21 +471,45 @@ public func ~= (_ sequence: S, _ e // MARK: - Where.Expression where V: Optional +/** + Creates a `Where` clause by comparing if an expression is less than a value + ``` + let childsPet = CoreStore.fetchOne(From().where((\.master ~ \.age) < 10)) + ``` + */ public func < (_ lhs: Where.Expression, _ rhs: V) -> Where { return Where(expression: lhs, function: "<", operand: rhs) } +/** + Creates a `Where` clause by comparing if an expression is less than or equal to a value + ``` + let childsPet = CoreStore.fetchOne(From().where((\.master ~ \.age) <= 10)) + ``` + */ public func <= (_ lhs: Where.Expression, _ rhs: V?) -> Where { return Where(expression: lhs, function: "<=", operand: rhs) } +/** + Creates a `Where` clause by comparing if an expression is greater than a value + ``` + let teensPet = CoreStore.fetchOne(From().where((\.master ~ \.age) > 10)) + ``` + */ public func > (_ lhs: Where.Expression, _ rhs: V) -> Where { return Where(expression: lhs, function: ">", operand: rhs) } +/** + Creates a `Where` clause by comparing if an expression is greater than or equal to a value + ``` + let teensPet = CoreStore.fetchOne(From().where((\.master ~ \.age) >= 10)) + ``` + */ public func >= (_ lhs: Where.Expression, _ rhs: V?) -> Where { return Where(expression: lhs, function: ">=", operand: rhs) @@ -296,6 +520,12 @@ public func >= (_ lhs: Where.Ex extension KeyPath where Root: NSManagedObject, Value: AllowedObjectiveCCollectionKeyPathValue { + /** + Creates a `Where.Expression` clause for COUNT + ``` + let dogsWithPlaymates = CoreStore.fetchAll(From().where((\.master ~ \.pets).count() > 1)) + ``` + */ public func count() -> Where.Expression.CollectionTarget, Int> { return .init(self.cs_keyPathString, "@count") @@ -306,6 +536,12 @@ extension KeyPath where Root: NSManagedObject, Value: AllowedObjectiveCCollectio extension Where.Expression where D: NSManagedObject, T == Where.CollectionTarget, V: AllowedObjectiveCCollectionKeyPathValue { + /** + Creates a `Where.Expression` clause for COUNT + ``` + let dogsWithPlaymates = CoreStore.fetchAll(From().where((\.master ~ \.pets).count() > 1)) + ``` + */ public func count() -> Where.Expression { return .init(self.cs_keyPathString, "@count") @@ -317,16 +553,34 @@ extension Where.Expression where D: NSManagedObject, T == Where.CollectionTar extension Where.Expression where D: NSManagedObject, T == Where.CollectionTarget, V: AllowedObjectiveCKeyPathValue { + /** + Creates a `Where.Expression` clause for ANY + ``` + let dogsWithBadNamingSense = CoreStore.fetchAll(From().where((\.master ~ \.pets ~ \.name).any() > "Spot")) + ``` + */ public func any() -> Where.Expression { return .init("ANY " + self.cs_keyPathString) } + /** + Creates a `Where.Expression` clause for ALL + ``` + let allPlaymatePuppies = CoreStore.fetchAll(From().where((\.master ~ \.pets ~ \.age).all() > 5)) + ``` + */ public func all() -> Where.Expression { return .init("ALL " + self.cs_keyPathString) } + /** + Creates a `Where.Expression` clause for NONE + ``` + let dogs = CoreStore.fetchAll(From().where((\.master ~ \.pets ~ \.name).any() > "Spot")) + ``` + */ public func none() -> Where.Expression { return .init("NONE " + self.cs_keyPathString) @@ -338,6 +592,12 @@ extension Where.Expression where D: NSManagedObject, T == Where.CollectionTar extension KeyPath where Root: CoreStoreObject, Value: AllowedCoreStoreObjectCollectionKeyPathValue { + /** + Creates a `Where.Expression` clause for COUNT + ``` + let dogsWithPlaymates = CoreStore.fetchAll(From().where((\.master ~ \.pets).count() > 1)) + ``` + */ public func count() -> Where.Expression.CollectionTarget, Int> { return .init(Root.meta[keyPath: self].cs_keyPathString, "@count") @@ -349,21 +609,45 @@ extension KeyPath where Root: CoreStoreObject, Value: AllowedCoreStoreObjectColl extension Where.Expression where D: CoreStoreObject, T == Where.CollectionTarget { + /** + Creates a `Where.Expression` clause for COUNT + ``` + let dogsWithPlaymates = CoreStore.fetchAll(From().where((\.master ~ \.pets).count() > 1)) + ``` + */ public func count() -> Where.Expression { return .init(self.cs_keyPathString, "@count") } + /** + Creates a `Where.Expression` clause for ANY + ``` + let dogsWithBadNamingSense = CoreStore.fetchAll(From().where((\.master ~ \.pets ~ \.name).any() > "Spot")) + ``` + */ public func any() -> Where.Expression { return .init("ANY " + self.cs_keyPathString) } + /** + Creates a `Where.Expression` clause for ALL + ``` + let allPlaymatePuppies = CoreStore.fetchAll(From().where((\.master ~ \.pets ~ \.age).all() > 5)) + ``` + */ public func all() -> Where.Expression { return .init("ALL " + self.cs_keyPathString) } + /** + Creates a `Where.Expression` clause for NONE + ``` + let dogs = CoreStore.fetchAll(From().where((\.master ~ \.pets ~ \.name).any() > "Spot")) + ``` + */ public func none() -> Where.Expression { return .init("NONE " + self.cs_keyPathString) diff --git a/Sources/WhereClauseType.swift b/Sources/WhereClauseType.swift index 489435c..468afc7 100644 --- a/Sources/WhereClauseType.swift +++ b/Sources/WhereClauseType.swift @@ -29,7 +29,7 @@ import Foundation // MARK: - WhereClauseType /** - Abstracts the `Where` clause for protocol utilities. + Abstracts the `Where` clause for protocol utilities. Typically used only for utility method generic constraints. */ public protocol WhereClauseType: AnyWhereClause {