0001 // Condition.swift 0002 // 0003 // The MIT License (MIT) 0004 // 0005 // Copyright (c) 2015 Formbound 0006 // 0007 // Permission is hereby granted, free of charge, to any person obtaining a copy 0008 // of this software and associated documentation files (the "Software"), to deal 0009 // in the Software without restriction, including without limitation the rights 0010 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 0011 // copies of the Software, and to permit persons to whom the Software is 0012 // furnished to do so, subject to the following conditions: 0013 // 0014 // The above copyright notice and this permission notice shall be included in all 0015 // copies or substantial portions of the Software. 0016 // 0017 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0018 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0019 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0020 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0021 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 0022 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 0023 // SOFTWARE. 0024 0025 public indirect enum Condition: StatementConvertible { 0026 public enum Value
Condition.swift:43 case And([Condition])Condition.swift:44 case Or([Condition])Condition.swift:46 case Not(Condition)Condition.swift:88 return (!Condition.In(key, values)).statementWithParameterOffset(¶meterOffset)Condition.swift:104 public prefix func ! (condition: Condition) -> Condition {Condition.swift:104 public prefix func ! (condition: Condition) -> Condition {Condition.swift:108 public func && (lhs: Condition, rhs: Condition) -> Condition {Condition.swift:108 public func && (lhs: Condition, rhs: Condition) -> Condition {Condition.swift:108 public func && (lhs: Condition, rhs: Condition) -> Condition {Condition.swift:112 public func || (lhs: Condition, rhs: Condition) -> Condition {Condition.swift:112 public func || (lhs: Condition, rhs: Condition) -> Condition {Condition.swift:112 public func || (lhs: Condition, rhs: Condition) -> Condition {Model.swift:55 public func containedIn(values: [ValueConvertible?]) -> Condition {Model.swift:59 public func containedIn(values: ValueConvertible?...) -> Condition {Model.swift:63 public func notContainedIn(values: [ValueConvertible?]) -> Condition {Model.swift:67 public func notContainedIn(values: ValueConvertible?...) -> Condition {Model.swift:72 public func == <T: ModelFieldset>(lhs: T, rhs: ValueConvertible?) -> Condition {Model.swift:76 public func == <L: ModelFieldset, R: ModelFieldset>(lhs: L, rhs: R) -> Condition {Model.swift:80 public func > <T: ModelFieldset>(lhs: T, rhs: ValueConvertible?) -> Condition {Model.swift:84 public func > <L: ModelFieldset, R: ModelFieldset>(lhs: L, rhs: R) -> Condition {Model.swift:89 public func >= <T: ModelFieldset>(lhs: T, rhs: ValueConvertible?) -> Condition {Model.swift:93 public func >= <L: ModelFieldset, R: ModelFieldset>(lhs: L, rhs: R) -> Condition {Model.swift:98 public func < <T: ModelFieldset>(lhs: T, rhs: ValueConvertible?) -> Condition {Model.swift:102 public func < <L: ModelFieldset, R: ModelFieldset>(lhs: L, rhs: R) -> Condition {Model.swift:107 public func <= <T: ModelFieldset>(lhs: T, rhs: ValueConvertible?) -> Condition {Model.swift:111 public func <= <L: ModelFieldset, R: ModelFieldset>(lhs: L, rhs: R) -> Condition {Query.swift:41 var condition: Condition? { get }Query.swift:88 internal var condition: Condition?Query.swift:185 internal var condition: Condition?Query.swift:218 public func filter(condition: Condition) -> Select {Query.swift:219 let newCondition: Condition{ 0027 case Value
Condition.swift:31 case Equals(String, Value)Condition.swift:33 case GreaterThan(String, Value)Condition.swift:34 case GreaterThanOrEquals(String, Value)Condition.swift:36 case LessThan(String, Value)Condition.swift:37 case LessThanOrEquals(String, Value)Condition.swift:51 func statementWithKeyValue(key: String, _ op: String, _ value: Value) -> Statement {(ValueConvertible?) 0028 case Property
Condition.swift:53 case .Value(let value):Model.swift:73 return .Equals(lhs.qualifiedName, .Value(rhs))Model.swift:81 return .GreaterThan(lhs.qualifiedName, .Value(rhs))Model.swift:90 return .GreaterThanOrEquals(lhs.qualifiedName, .Value(rhs))Model.swift:99 return .LessThan(lhs.qualifiedName, .Value(rhs))Model.swift:108 return .LessThanOrEquals(lhs.qualifiedName, .Value(rhs))(String) 0029 } 0030 0031 case Equals
Condition.swift:57 case .Property(let name):Model.swift:77 return .Equals(lhs.qualifiedName, .Property(rhs.qualifiedName))Model.swift:85 return .GreaterThan(lhs.qualifiedName, .Property(rhs.qualifiedName))Model.swift:94 return .GreaterThanOrEquals(lhs.qualifiedName, .Property(rhs.qualifiedName))Model.swift:103 return .LessThan(lhs.qualifiedName, .Property(rhs.qualifiedName))Model.swift:112 return .LessThanOrEquals(lhs.qualifiedName, .Property(rhs.qualifiedName))(String, Value) 0032 0033 case GreaterThan
Condition.swift:63 case .Equals(let key, let value):Model.swift:73 return .Equals(lhs.qualifiedName, .Value(rhs))Model.swift:77 return .Equals(lhs.qualifiedName, .Property(rhs.qualifiedName))(String, Value) 0034 case GreaterThanOrEquals
Condition.swift:66 case .GreaterThan(let key, let value):Model.swift:81 return .GreaterThan(lhs.qualifiedName, .Value(rhs))Model.swift:85 return .GreaterThan(lhs.qualifiedName, .Property(rhs.qualifiedName))(String, Value) 0035 0036 case LessThan
Condition.swift:69 case .GreaterThanOrEquals(let key, let value):Model.swift:90 return .GreaterThanOrEquals(lhs.qualifiedName, .Value(rhs))Model.swift:94 return .GreaterThanOrEquals(lhs.qualifiedName, .Property(rhs.qualifiedName))(String, Value) 0037 case LessThanOrEquals
Condition.swift:72 case .LessThan(let key, let value):Model.swift:99 return .LessThan(lhs.qualifiedName, .Value(rhs))Model.swift:103 return .LessThan(lhs.qualifiedName, .Property(rhs.qualifiedName))(String, Value) 0038 0039 0040 case In
Condition.swift:75 case .LessThanOrEquals(let key, let value):Model.swift:108 return .LessThanOrEquals(lhs.qualifiedName, .Value(rhs))Model.swift:112 return .LessThanOrEquals(lhs.qualifiedName, .Property(rhs.qualifiedName))(String, [ValueConvertible?]) 0041 case NotIn
Condition.swift:79 case .In(let key, let values):Condition.swift:88 return (!Condition.In(key, values)).statementWithParameterOffset(¶meterOffset)Model.swift:56 return .In(qualifiedName, values)Model.swift:60 return .In(qualifiedName, values)(String, [ValueConvertible?]) 0042 0043 case And
Condition.swift:87 case .NotIn(let key, let values):Model.swift:64 return .NotIn(qualifiedName, values)Model.swift:68 return .NotIn(qualifiedName, values)([Condition]) 0044 case Or
Condition.swift:90 case .And(let conditions):Condition.swift:109 return .And([lhs, rhs])Query.swift:221 newCondition = .And([existing, condition])([Condition]) 0045 0046 case Not
Condition.swift:93 case .Or(let conditions):Condition.swift:113 return .Or([lhs, rhs])(Condition) 0047 0048 0049 public func statementWithParameterOffset
Condition.swift:96 case .Not(let condition):Condition.swift:105 return .Not(condition)(inout parameterOffset: Int) -> Statement { 0050 0051 func statementWithKeyValue(key: String, _ op: String, _ value: Value) -> Statement { 0052 switch value { 0053 case .Value(let value): 0054 let result = Statement("\(key) \(op) $\(parameterOffset)", parameters: [value]) 0055 parameterOffset += 1 0056 return result 0057 case .Property(let name): 0058 return Statement("\(key) \(op) \(name)", parameters: []) 0059 } 0060 } 0061 0062 switch self { 0063 case .Equals(let key, let value): 0064 return statementWithKeyValue(key, "=", value) 0065 0066 case .GreaterThan(let key, let value): 0067 return statementWithKeyValue(key, ">", value) 0068 0069 case .GreaterThanOrEquals(let key, let value): 0070 return statementWithKeyValue(key, ">=", value) 0071 0072 case .LessThan(let key, let value): 0073 return statementWithKeyValue(key, "<", value) 0074 0075 case .LessThanOrEquals(let key, let value): 0076 return statementWithKeyValue(key, "<=", value) 0077 0078 0079 case .In(let key, let values): 0080 0081 let parameterString = (parameterOffset..<parameterOffset + values.count).map { 0082 return "$\($0)" 0083 }.joinWithSeparator(", ") 0084 0085 return Statement("\(key) IN(\(parameterString))", parameters: values) 0086 0087 case .NotIn(let key, let values): 0088 return (!Condition.In(key, values)).statementWithParameterOffset(¶meterOffset) 0089 0090 case .And(let conditions): 0091 return conditions.statementWithParameterOffset(¶meterOffset, joinBy: "AND").isolate() 0092 0093 case .Or(let conditions): 0094 return conditions.statementWithParameterOffset(¶meterOffset, joinBy: "OR").isolate() 0095 0096 case .Not(let condition): 0097 var statement = condition.statementWithParameterOffset(¶meterOffset).isolate() 0098 statement.prependComponent("NOT") 0099 return statement 0100 } 0101 } 0102 } 0103 0104 public prefix func ! (condition: Condition) -> Condition { 0105 return .Not(condition) 0106 } 0107 0108 public func && (lhs: Condition, rhs: Condition) -> Condition { 0109 return .And([lhs, rhs]) 0110 } 0111 0112 public func || (lhs: Condition, rhs: Condition) -> Condition { 0113 return .Or([lhs, rhs]) 0114 }
Condition.swift:88 return (!Condition.In(key, values)).statementWithParameterOffset(¶meterOffset)Condition.swift:97 var statement = condition.statementWithParameterOffset(¶meterOffset).isolate()Query.swift:98 statement.merge(condition.statementWithParameterOffset(¶meterOffset))Query.swift:260 statement.merge(condition.statementWithParameterOffset(¶meterOffset))