diff --git a/Sources/SQLite/Helpers.swift b/Sources/SQLite/Helpers.swift index ac831667..115ea5c6 100644 --- a/Sources/SQLite/Helpers.swift +++ b/Sources/SQLite/Helpers.swift @@ -98,18 +98,6 @@ extension String { } -func infix(_ lhs: Expressible, _ rhs: Expressible, wrap: Bool = true, function: String = #function) -> Expression { - return function.infix(lhs, rhs, wrap: wrap) -} - -func wrap(_ expression: Expressible, function: String = #function) -> Expression { - return function.wrap(expression) -} - -func wrap(_ expressions: [Expressible], function: String = #function) -> Expression { - return function.wrap(", ".join(expressions)) -} - func transcode(_ literal: Binding?) -> String { guard let literal = literal else { return "NULL" } diff --git a/Sources/SQLite/Typed/AggregateFunctions.swift b/Sources/SQLite/Typed/AggregateFunctions.swift index 249bbe60..2ec28288 100644 --- a/Sources/SQLite/Typed/AggregateFunctions.swift +++ b/Sources/SQLite/Typed/AggregateFunctions.swift @@ -22,6 +22,19 @@ // THE SOFTWARE. // +private enum Function: String { + case count + case max + case min + case avg + case sum + case total + + func wrap(_ expression: Expressible) -> Expression { + return self.rawValue.wrap(expression) + } +} + extension ExpressionType where UnderlyingType : Value { /// Builds a copy of the expression prefixed with the `DISTINCT` keyword. @@ -48,7 +61,7 @@ extension ExpressionType where UnderlyingType : Value { /// - Returns: A copy of the expression wrapped with the `count` aggregate /// function. public var count: Expression { - return wrap(self) + return Function.count.wrap(self) } } @@ -79,7 +92,7 @@ extension ExpressionType where UnderlyingType : _OptionalType, UnderlyingType.Wr /// - Returns: A copy of the expression wrapped with the `count` aggregate /// function. public var count: Expression { - return wrap(self) + return Function.count.wrap(self) } } @@ -96,7 +109,7 @@ extension ExpressionType where UnderlyingType : Value, UnderlyingType.Datatype : /// - Returns: A copy of the expression wrapped with the `max` aggregate /// function. public var max: Expression { - return wrap(self) + return Function.max.wrap(self) } /// Builds a copy of the expression wrapped with the `min` aggregate @@ -109,7 +122,7 @@ extension ExpressionType where UnderlyingType : Value, UnderlyingType.Datatype : /// - Returns: A copy of the expression wrapped with the `min` aggregate /// function. public var min: Expression { - return wrap(self) + return Function.min.wrap(self) } } @@ -126,7 +139,7 @@ extension ExpressionType where UnderlyingType : _OptionalType, UnderlyingType.Wr /// - Returns: A copy of the expression wrapped with the `max` aggregate /// function. public var max: Expression { - return wrap(self) + return Function.max.wrap(self) } /// Builds a copy of the expression wrapped with the `min` aggregate @@ -139,7 +152,7 @@ extension ExpressionType where UnderlyingType : _OptionalType, UnderlyingType.Wr /// - Returns: A copy of the expression wrapped with the `min` aggregate /// function. public var min: Expression { - return wrap(self) + return Function.min.wrap(self) } } @@ -156,7 +169,7 @@ extension ExpressionType where UnderlyingType : Value, UnderlyingType.Datatype : /// - Returns: A copy of the expression wrapped with the `min` aggregate /// function. public var average: Expression { - return "avg".wrap(self) + return Function.avg.wrap(self) } /// Builds a copy of the expression wrapped with the `sum` aggregate @@ -169,7 +182,7 @@ extension ExpressionType where UnderlyingType : Value, UnderlyingType.Datatype : /// - Returns: A copy of the expression wrapped with the `min` aggregate /// function. public var sum: Expression { - return wrap(self) + return Function.sum.wrap(self) } /// Builds a copy of the expression wrapped with the `total` aggregate @@ -182,7 +195,7 @@ extension ExpressionType where UnderlyingType : Value, UnderlyingType.Datatype : /// - Returns: A copy of the expression wrapped with the `min` aggregate /// function. public var total: Expression { - return wrap(self) + return Function.total.wrap(self) } } @@ -199,7 +212,7 @@ extension ExpressionType where UnderlyingType : _OptionalType, UnderlyingType.Wr /// - Returns: A copy of the expression wrapped with the `min` aggregate /// function. public var average: Expression { - return "avg".wrap(self) + return Function.avg.wrap(self) } /// Builds a copy of the expression wrapped with the `sum` aggregate @@ -212,7 +225,7 @@ extension ExpressionType where UnderlyingType : _OptionalType, UnderlyingType.Wr /// - Returns: A copy of the expression wrapped with the `min` aggregate /// function. public var sum: Expression { - return wrap(self) + return Function.sum.wrap(self) } /// Builds a copy of the expression wrapped with the `total` aggregate @@ -225,7 +238,7 @@ extension ExpressionType where UnderlyingType : _OptionalType, UnderlyingType.Wr /// - Returns: A copy of the expression wrapped with the `min` aggregate /// function. public var total: Expression { - return wrap(self) + return Function.total.wrap(self) } } @@ -233,7 +246,7 @@ extension ExpressionType where UnderlyingType : _OptionalType, UnderlyingType.Wr extension ExpressionType where UnderlyingType == Int { static func count(_ star: Star) -> Expression { - return wrap(star(nil, nil)) + return Function.count.wrap(star(nil, nil)) } } diff --git a/Sources/SQLite/Typed/CoreFunctions.swift b/Sources/SQLite/Typed/CoreFunctions.swift index d7995b95..068dcf02 100644 --- a/Sources/SQLite/Typed/CoreFunctions.swift +++ b/Sources/SQLite/Typed/CoreFunctions.swift @@ -24,6 +24,40 @@ import Foundation +private enum Function: String { + case abs + case round + case random + case randomblob + case zeroblob + case length + case lower + case upper + case ltrim + case rtrim + case trim + case replace + case substr + case like = "LIKE" + case `in` = "IN" + case glob = "GLOB" + case match = "MATCH" + case regexp = "REGEXP" + case collate = "COLLATE" + case ifnull + + func infix(_ lhs: Expressible, _ rhs: Expressible, wrap: Bool = true) -> Expression { + return self.rawValue.infix(lhs, rhs, wrap: wrap) + } + + func wrap(_ expression: Expressible) -> Expression { + return self.rawValue.wrap(expression) + } + + func wrap(_ expressions: [Expressible]) -> Expression { + return self.rawValue.wrap(", ".join(expressions)) + } +} extension ExpressionType where UnderlyingType : Number { @@ -35,7 +69,7 @@ extension ExpressionType where UnderlyingType : Number { /// /// - Returns: A copy of the expression wrapped with the `abs` function. public var absoluteValue : Expression { - return "abs".wrap(self) + return Function.abs.wrap(self) } } @@ -50,7 +84,7 @@ extension ExpressionType where UnderlyingType : _OptionalType, UnderlyingType.Wr /// /// - Returns: A copy of the expression wrapped with the `abs` function. public var absoluteValue : Expression { - return "abs".wrap(self) + return Function.abs.wrap(self) } } @@ -68,9 +102,9 @@ extension ExpressionType where UnderlyingType == Double { /// - Returns: A copy of the expression wrapped with the `round` function. public func round(_ precision: Int? = nil) -> Expression { guard let precision = precision else { - return wrap([self]) + return Function.round.wrap([self]) } - return wrap([self, Int(precision)]) + return Function.round.wrap([self, Int(precision)]) } } @@ -88,9 +122,9 @@ extension ExpressionType where UnderlyingType == Double? { /// - Returns: A copy of the expression wrapped with the `round` function. public func round(_ precision: Int? = nil) -> Expression { guard let precision = precision else { - return wrap(self) + return Function.round.wrap(self) } - return wrap([self, Int(precision)]) + return Function.round.wrap([self, Int(precision)]) } } @@ -104,7 +138,7 @@ extension ExpressionType where UnderlyingType : Value, UnderlyingType.Datatype = /// /// - Returns: An expression calling the `random` function. public static func random() -> Expression { - return "random".wrap([]) + return Function.random.wrap([]) } } @@ -120,7 +154,7 @@ extension ExpressionType where UnderlyingType == Data { /// /// - Returns: An expression calling the `randomblob` function. public static func random(_ length: Int) -> Expression { - return "randomblob".wrap([]) + return Function.randomblob.wrap([]) } /// Builds an expression representing the `zeroblob` function. @@ -132,7 +166,7 @@ extension ExpressionType where UnderlyingType == Data { /// /// - Returns: An expression calling the `zeroblob` function. public static func allZeros(_ length: Int) -> Expression { - return "zeroblob".wrap([]) + return Function.zeroblob.wrap([]) } /// Builds a copy of the expression wrapped with the `length` function. @@ -143,7 +177,7 @@ extension ExpressionType where UnderlyingType == Data { /// /// - Returns: A copy of the expression wrapped with the `length` function. public var length: Expression { - return wrap(self) + return Function.length.wrap(self) } } @@ -158,7 +192,7 @@ extension ExpressionType where UnderlyingType == Data? { /// /// - Returns: A copy of the expression wrapped with the `length` function. public var length: Expression { - return wrap(self) + return Function.length.wrap(self) } } @@ -173,7 +207,7 @@ extension ExpressionType where UnderlyingType == String { /// /// - Returns: A copy of the expression wrapped with the `length` function. public var length: Expression { - return wrap(self) + return Function.length.wrap(self) } /// Builds a copy of the expression wrapped with the `lower` function. @@ -184,7 +218,7 @@ extension ExpressionType where UnderlyingType == String { /// /// - Returns: A copy of the expression wrapped with the `lower` function. public var lowercaseString: Expression { - return "lower".wrap(self) + return Function.lower.wrap(self) } /// Builds a copy of the expression wrapped with the `upper` function. @@ -195,7 +229,7 @@ extension ExpressionType where UnderlyingType == String { /// /// - Returns: A copy of the expression wrapped with the `upper` function. public var uppercaseString: Expression { - return "upper".wrap(self) + return Function.upper.wrap(self) } /// Builds a copy of the expression appended with a `LIKE` query against the @@ -242,9 +276,9 @@ extension ExpressionType where UnderlyingType == String { /// the given pattern. public func like(_ pattern: Expression, escape character: Character? = nil) -> Expression { guard let character = character else { - return "LIKE".infix(self, pattern) + return Function.like.infix(self, pattern) } - let like: Expression = "LIKE".infix(self, pattern, wrap: false) + let like: Expression = Function.like.infix(self, pattern, wrap: false) return Expression("(\(like.template) ESCAPE ?)", like.bindings + [String(character)]) } @@ -260,7 +294,7 @@ extension ExpressionType where UnderlyingType == String { /// - Returns: A copy of the expression appended with a `GLOB` query against /// the given pattern. public func glob(_ pattern: String) -> Expression { - return "GLOB".infix(self, pattern) + return Function.glob.infix(self, pattern) } /// Builds a copy of the expression appended with a `MATCH` query against @@ -275,7 +309,7 @@ extension ExpressionType where UnderlyingType == String { /// - Returns: A copy of the expression appended with a `MATCH` query /// against the given pattern. public func match(_ pattern: String) -> Expression { - return "MATCH".infix(self, pattern) + return Function.match.infix(self, pattern) } /// Builds a copy of the expression appended with a `REGEXP` query against @@ -286,7 +320,7 @@ extension ExpressionType where UnderlyingType == String { /// - Returns: A copy of the expression appended with a `REGEXP` query /// against the given pattern. public func regexp(_ pattern: String) -> Expression { - return "REGEXP".infix(self, pattern) + return Function.regexp.infix(self, pattern) } /// Builds a copy of the expression appended with a `COLLATE` clause with @@ -301,7 +335,7 @@ extension ExpressionType where UnderlyingType == String { /// - Returns: A copy of the expression appended with a `COLLATE` clause /// with the given sequence. public func collate(_ collation: Collation) -> Expression { - return "COLLATE".infix(self, collation) + return Function.collate.infix(self, collation) } /// Builds a copy of the expression wrapped with the `ltrim` function. @@ -317,9 +351,9 @@ extension ExpressionType where UnderlyingType == String { /// - Returns: A copy of the expression wrapped with the `ltrim` function. public func ltrim(_ characters: Set? = nil) -> Expression { guard let characters = characters else { - return wrap(self) + return Function.ltrim.wrap(self) } - return wrap([self, String(characters)]) + return Function.ltrim.wrap([self, String(characters)]) } /// Builds a copy of the expression wrapped with the `rtrim` function. @@ -335,9 +369,9 @@ extension ExpressionType where UnderlyingType == String { /// - Returns: A copy of the expression wrapped with the `rtrim` function. public func rtrim(_ characters: Set? = nil) -> Expression { guard let characters = characters else { - return wrap(self) + return Function.rtrim.wrap(self) } - return wrap([self, String(characters)]) + return Function.rtrim.wrap([self, String(characters)]) } /// Builds a copy of the expression wrapped with the `trim` function. @@ -353,9 +387,9 @@ extension ExpressionType where UnderlyingType == String { /// - Returns: A copy of the expression wrapped with the `trim` function. public func trim(_ characters: Set? = nil) -> Expression { guard let characters = characters else { - return wrap([self]) + return Function.trim.wrap([self]) } - return wrap([self, String(characters)]) + return Function.trim.wrap([self, String(characters)]) } /// Builds a copy of the expression wrapped with the `replace` function. @@ -372,14 +406,14 @@ extension ExpressionType where UnderlyingType == String { /// /// - Returns: A copy of the expression wrapped with the `replace` function. public func replace(_ pattern: String, with replacement: String) -> Expression { - return "replace".wrap([self, pattern, replacement]) + return Function.replace.wrap([self, pattern, replacement]) } public func substring(_ location: Int, length: Int? = nil) -> Expression { guard let length = length else { - return "substr".wrap([self, location]) + return Function.substr.wrap([self, location]) } - return "substr".wrap([self, location, length]) + return Function.substr.wrap([self, location, length]) } public subscript(range: Range) -> Expression { @@ -398,7 +432,7 @@ extension ExpressionType where UnderlyingType == String? { /// /// - Returns: A copy of the expression wrapped with the `length` function. public var length: Expression { - return wrap(self) + return Function.length.wrap(self) } /// Builds a copy of the expression wrapped with the `lower` function. @@ -409,7 +443,7 @@ extension ExpressionType where UnderlyingType == String? { /// /// - Returns: A copy of the expression wrapped with the `lower` function. public var lowercaseString: Expression { - return "lower".wrap(self) + return Function.lower.wrap(self) } /// Builds a copy of the expression wrapped with the `upper` function. @@ -420,7 +454,7 @@ extension ExpressionType where UnderlyingType == String? { /// /// - Returns: A copy of the expression wrapped with the `upper` function. public var uppercaseString: Expression { - return "upper".wrap(self) + return Function.upper.wrap(self) } /// Builds a copy of the expression appended with a `LIKE` query against the @@ -443,7 +477,7 @@ extension ExpressionType where UnderlyingType == String? { /// the given pattern. public func like(_ pattern: String, escape character: Character? = nil) -> Expression { guard let character = character else { - return "LIKE".infix(self, pattern) + return Function.like.infix(self, pattern) } return Expression("(\(template) LIKE ? ESCAPE ?)", bindings + [pattern, String(character)]) } @@ -467,9 +501,9 @@ extension ExpressionType where UnderlyingType == String? { /// the given pattern. public func like(_ pattern: Expression, escape character: Character? = nil) -> Expression { guard let character = character else { - return "LIKE".infix(self, pattern) + return Function.like.infix(self, pattern) } - let like: Expression = "LIKE".infix(self, pattern, wrap: false) + let like: Expression = Function.like.infix(self, pattern, wrap: false) return Expression("(\(like.template) ESCAPE ?)", like.bindings + [String(character)]) } @@ -485,7 +519,7 @@ extension ExpressionType where UnderlyingType == String? { /// - Returns: A copy of the expression appended with a `GLOB` query against /// the given pattern. public func glob(_ pattern: String) -> Expression { - return "GLOB".infix(self, pattern) + return Function.glob.infix(self, pattern) } /// Builds a copy of the expression appended with a `MATCH` query against @@ -500,7 +534,7 @@ extension ExpressionType where UnderlyingType == String? { /// - Returns: A copy of the expression appended with a `MATCH` query /// against the given pattern. public func match(_ pattern: String) -> Expression { - return "MATCH".infix(self, pattern) + return Function.match.infix(self, pattern) } /// Builds a copy of the expression appended with a `REGEXP` query against @@ -511,7 +545,7 @@ extension ExpressionType where UnderlyingType == String? { /// - Returns: A copy of the expression appended with a `REGEXP` query /// against the given pattern. public func regexp(_ pattern: String) -> Expression { - return "REGEXP".infix(self, pattern) + return Function.regexp.infix(self, pattern) } /// Builds a copy of the expression appended with a `COLLATE` clause with @@ -526,7 +560,7 @@ extension ExpressionType where UnderlyingType == String? { /// - Returns: A copy of the expression appended with a `COLLATE` clause /// with the given sequence. public func collate(_ collation: Collation) -> Expression { - return "COLLATE".infix(self, collation) + return Function.collate.infix(self, collation) } /// Builds a copy of the expression wrapped with the `ltrim` function. @@ -542,9 +576,9 @@ extension ExpressionType where UnderlyingType == String? { /// - Returns: A copy of the expression wrapped with the `ltrim` function. public func ltrim(_ characters: Set? = nil) -> Expression { guard let characters = characters else { - return wrap(self) + return Function.ltrim.wrap(self) } - return wrap([self, String(characters)]) + return Function.ltrim.wrap([self, String(characters)]) } /// Builds a copy of the expression wrapped with the `rtrim` function. @@ -560,9 +594,9 @@ extension ExpressionType where UnderlyingType == String? { /// - Returns: A copy of the expression wrapped with the `rtrim` function. public func rtrim(_ characters: Set? = nil) -> Expression { guard let characters = characters else { - return wrap(self) + return Function.rtrim.wrap(self) } - return wrap([self, String(characters)]) + return Function.rtrim.wrap([self, String(characters)]) } /// Builds a copy of the expression wrapped with the `trim` function. @@ -578,9 +612,9 @@ extension ExpressionType where UnderlyingType == String? { /// - Returns: A copy of the expression wrapped with the `trim` function. public func trim(_ characters: Set? = nil) -> Expression { guard let characters = characters else { - return wrap(self) + return Function.trim.wrap(self) } - return wrap([self, String(characters)]) + return Function.trim.wrap([self, String(characters)]) } /// Builds a copy of the expression wrapped with the `replace` function. @@ -597,7 +631,7 @@ extension ExpressionType where UnderlyingType == String? { /// /// - Returns: A copy of the expression wrapped with the `replace` function. public func replace(_ pattern: String, with replacement: String) -> Expression { - return "replace".wrap([self, pattern, replacement]) + return Function.replace.wrap([self, pattern, replacement]) } /// Builds a copy of the expression wrapped with the `substr` function. @@ -617,9 +651,9 @@ extension ExpressionType where UnderlyingType == String? { /// - Returns: A copy of the expression wrapped with the `substr` function. public func substring(_ location: Int, length: Int? = nil) -> Expression { guard let length = length else { - return "substr".wrap([self, location]) + return Function.substr.wrap([self, location]) } - return "substr".wrap([self, location, length]) + return Function.substr.wrap([self, location, length]) } /// Builds a copy of the expression wrapped with the `substr` function. @@ -652,7 +686,7 @@ extension Collection where Iterator.Element : Value { /// the collection. public func contains(_ expression: Expression) -> Expression { let templates = [String](repeating: "?", count: count).joined(separator: ", ") - return "IN".infix(expression, Expression("(\(templates))", map { $0.datatypeValue })) + return Function.in.infix(expression, Expression("(\(templates))", map { $0.datatypeValue })) } /// Builds a copy of the expression prepended with an `IN` check against the @@ -668,7 +702,7 @@ extension Collection where Iterator.Element : Value { /// the collection. public func contains(_ expression: Expression) -> Expression { let templates = [String](repeating: "?", count: count).joined(separator: ", ") - return "IN".infix(expression, Expression("(\(templates))", map { $0.datatypeValue })) + return Function.in.infix(expression, Expression("(\(templates))", map { $0.datatypeValue })) } } @@ -694,9 +728,9 @@ extension String { /// the given pattern. public func like(_ pattern: Expression, escape character: Character? = nil) -> Expression { guard let character = character else { - return "LIKE".infix(self, pattern) + return Function.like.infix(self, pattern) } - let like: Expression = "LIKE".infix(self, pattern, wrap: false) + let like: Expression = Function.like.infix(self, pattern, wrap: false) return Expression("(\(like.template) ESCAPE ?)", like.bindings + [String(character)]) } @@ -718,7 +752,7 @@ extension String { /// - Returns: A copy of the given expressions wrapped with the `ifnull` /// function. public func ??(optional: Expression, defaultValue: V) -> Expression { - return "ifnull".wrap([optional, defaultValue]) + return Function.ifnull.wrap([optional, defaultValue]) } /// Builds a copy of the given expressions wrapped with the `ifnull` function. @@ -738,7 +772,7 @@ public func ??(optional: Expression, defaultValue: V) -> Expressi /// - Returns: A copy of the given expressions wrapped with the `ifnull` /// function. public func ??(optional: Expression, defaultValue: Expression) -> Expression { - return "ifnull".wrap([optional, defaultValue]) + return Function.ifnull.wrap([optional, defaultValue]) } /// Builds a copy of the given expressions wrapped with the `ifnull` function. @@ -758,5 +792,5 @@ public func ??(optional: Expression, defaultValue: Expression) /// - Returns: A copy of the given expressions wrapped with the `ifnull` /// function. public func ??(optional: Expression, defaultValue: Expression) -> Expression { - return "ifnull".wrap([optional, defaultValue]) + return Function.ifnull.wrap([optional, defaultValue]) } diff --git a/Sources/SQLite/Typed/Operators.swift b/Sources/SQLite/Typed/Operators.swift index d97e52b9..b5637ea3 100644 --- a/Sources/SQLite/Typed/Operators.swift +++ b/Sources/SQLite/Typed/Operators.swift @@ -24,266 +24,297 @@ // TODO: use `@warn_unused_result` by the time operator functions support it +private enum Operator: String { + case plus = "+" + case minus = "-" + case or = "OR" + case and = "AND" + case not = "NOT " + case mul = "*" + case div = "/" + case mod = "%" + case bitwiseLeft = "<<" + case bitwiseRight = ">>" + case bitwiseAnd = "&" + case bitwiseOr = "|" + case bitwiseXor = "~" + case eq = "=" + case neq = "!=" + case gt = ">" + case lt = "<" + case gte = ">=" + case lte = "<=" + case concatenate = "||" + + func infix(_ lhs: Expressible, _ rhs: Expressible, wrap: Bool = true) -> Expression { + return self.rawValue.infix(lhs, rhs, wrap: wrap) + } + + func wrap(_ expression: Expressible) -> Expression { + return self.rawValue.wrap(expression) + } +} + public func +(lhs: Expression, rhs: Expression) -> Expression { - return "||".infix(lhs, rhs) + return Operator.concatenate.infix(lhs, rhs) } public func +(lhs: Expression, rhs: Expression) -> Expression { - return "||".infix(lhs, rhs) + return Operator.concatenate.infix(lhs, rhs) } public func +(lhs: Expression, rhs: Expression) -> Expression { - return "||".infix(lhs, rhs) + return Operator.concatenate.infix(lhs, rhs) } public func +(lhs: Expression, rhs: Expression) -> Expression { - return "||".infix(lhs, rhs) + return Operator.concatenate.infix(lhs, rhs) } public func +(lhs: Expression, rhs: String) -> Expression { - return "||".infix(lhs, rhs) + return Operator.concatenate.infix(lhs, rhs) } public func +(lhs: Expression, rhs: String) -> Expression { - return "||".infix(lhs, rhs) + return Operator.concatenate.infix(lhs, rhs) } public func +(lhs: String, rhs: Expression) -> Expression { - return "||".infix(lhs, rhs) + return Operator.concatenate.infix(lhs, rhs) } public func +(lhs: String, rhs: Expression) -> Expression { - return "||".infix(lhs, rhs) + return Operator.concatenate.infix(lhs, rhs) } // MARK: - public func +(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.plus.infix(lhs, rhs) } public func +(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.plus.infix(lhs, rhs) } public func +(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.plus.infix(lhs, rhs) } public func +(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.plus.infix(lhs, rhs) } public func +(lhs: Expression, rhs: V) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.plus.infix(lhs, rhs) } public func +(lhs: Expression, rhs: V) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.plus.infix(lhs, rhs) } public func +(lhs: V, rhs: Expression) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.plus.infix(lhs, rhs) } public func +(lhs: V, rhs: Expression) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.plus.infix(lhs, rhs) } public func -(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.minus.infix(lhs, rhs) } public func -(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.minus.infix(lhs, rhs) } public func -(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.minus.infix(lhs, rhs) } public func -(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.minus.infix(lhs, rhs) } public func -(lhs: Expression, rhs: V) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.minus.infix(lhs, rhs) } public func -(lhs: Expression, rhs: V) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.minus.infix(lhs, rhs) } public func -(lhs: V, rhs: Expression) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.minus.infix(lhs, rhs) } public func -(lhs: V, rhs: Expression) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.minus.infix(lhs, rhs) } public func *(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.mul.infix(lhs, rhs) } public func *(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.mul.infix(lhs, rhs) } public func *(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.mul.infix(lhs, rhs) } public func *(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.mul.infix(lhs, rhs) } public func *(lhs: Expression, rhs: V) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.mul.infix(lhs, rhs) } public func *(lhs: Expression, rhs: V) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.mul.infix(lhs, rhs) } public func *(lhs: V, rhs: Expression) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.mul.infix(lhs, rhs) } public func *(lhs: V, rhs: Expression) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.mul.infix(lhs, rhs) } public func /(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.div.infix(lhs, rhs) } public func /(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.div.infix(lhs, rhs) } public func /(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.div.infix(lhs, rhs) } public func /(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.div.infix(lhs, rhs) } public func /(lhs: Expression, rhs: V) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.div.infix(lhs, rhs) } public func /(lhs: Expression, rhs: V) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.div.infix(lhs, rhs) } public func /(lhs: V, rhs: Expression) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.div.infix(lhs, rhs) } public func /(lhs: V, rhs: Expression) -> Expression where V.Datatype : Number { - return infix(lhs, rhs) + return Operator.div.infix(lhs, rhs) } public prefix func -(rhs: Expression) -> Expression where V.Datatype : Number { - return wrap(rhs) + return Operator.minus.wrap(rhs) } public prefix func -(rhs: Expression) -> Expression where V.Datatype : Number { - return wrap(rhs) + return Operator.minus.wrap(rhs) } // MARK: - public func %(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.mod.infix(lhs, rhs) } public func %(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.mod.infix(lhs, rhs) } public func %(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.mod.infix(lhs, rhs) } public func %(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.mod.infix(lhs, rhs) } public func %(lhs: Expression, rhs: V) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.mod.infix(lhs, rhs) } public func %(lhs: Expression, rhs: V) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.mod.infix(lhs, rhs) } public func %(lhs: V, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.mod.infix(lhs, rhs) } public func %(lhs: V, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.mod.infix(lhs, rhs) } public func <<(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseLeft.infix(lhs, rhs) } public func <<(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseLeft.infix(lhs, rhs) } public func <<(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseLeft.infix(lhs, rhs) } public func <<(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseLeft.infix(lhs, rhs) } public func <<(lhs: Expression, rhs: V) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseLeft.infix(lhs, rhs) } public func <<(lhs: Expression, rhs: V) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseLeft.infix(lhs, rhs) } public func <<(lhs: V, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseLeft.infix(lhs, rhs) } public func <<(lhs: V, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseLeft.infix(lhs, rhs) } public func >>(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseRight.infix(lhs, rhs) } public func >>(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseRight.infix(lhs, rhs) } public func >>(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseRight.infix(lhs, rhs) } public func >>(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseRight.infix(lhs, rhs) } public func >>(lhs: Expression, rhs: V) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseRight.infix(lhs, rhs) } public func >>(lhs: Expression, rhs: V) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseRight.infix(lhs, rhs) } public func >>(lhs: V, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseRight.infix(lhs, rhs) } public func >>(lhs: V, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseRight.infix(lhs, rhs) } public func &(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseAnd.infix(lhs, rhs) } public func &(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseAnd.infix(lhs, rhs) } public func &(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseAnd.infix(lhs, rhs) } public func &(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseAnd.infix(lhs, rhs) } public func &(lhs: Expression, rhs: V) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseAnd.infix(lhs, rhs) } public func &(lhs: Expression, rhs: V) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseAnd.infix(lhs, rhs) } public func &(lhs: V, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseAnd.infix(lhs, rhs) } public func &(lhs: V, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseAnd.infix(lhs, rhs) } public func |(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseOr.infix(lhs, rhs) } public func |(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseOr.infix(lhs, rhs) } public func |(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseOr.infix(lhs, rhs) } public func |(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseOr.infix(lhs, rhs) } public func |(lhs: Expression, rhs: V) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseOr.infix(lhs, rhs) } public func |(lhs: Expression, rhs: V) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseOr.infix(lhs, rhs) } public func |(lhs: V, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseOr.infix(lhs, rhs) } public func |(lhs: V, rhs: Expression) -> Expression where V.Datatype == Int64 { - return infix(lhs, rhs) + return Operator.bitwiseOr.infix(lhs, rhs) } public func ^(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { @@ -312,166 +343,166 @@ public func ^(lhs: V, rhs: Expression) -> Expression where V. } public prefix func ~(rhs: Expression) -> Expression where V.Datatype == Int64 { - return wrap(rhs) + return Operator.bitwiseXor.wrap(rhs) } public prefix func ~(rhs: Expression) -> Expression where V.Datatype == Int64 { - return wrap(rhs) + return Operator.bitwiseXor.wrap(rhs) } // MARK: - public func ==(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Equatable { - return "=".infix(lhs, rhs) + return Operator.eq.infix(lhs, rhs) } public func ==(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Equatable { - return "=".infix(lhs, rhs) + return Operator.eq.infix(lhs, rhs) } public func ==(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Equatable { - return "=".infix(lhs, rhs) + return Operator.eq.infix(lhs, rhs) } public func ==(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Equatable { - return "=".infix(lhs, rhs) + return Operator.eq.infix(lhs, rhs) } public func ==(lhs: Expression, rhs: V) -> Expression where V.Datatype : Equatable { - return "=".infix(lhs, rhs) + return Operator.eq.infix(lhs, rhs) } public func ==(lhs: Expression, rhs: V?) -> Expression where V.Datatype : Equatable { guard let rhs = rhs else { return "IS".infix(lhs, Expression(value: nil)) } - return "=".infix(lhs, rhs) + return Operator.eq.infix(lhs, rhs) } public func ==(lhs: V, rhs: Expression) -> Expression where V.Datatype : Equatable { - return "=".infix(lhs, rhs) + return Operator.eq.infix(lhs, rhs) } public func ==(lhs: V?, rhs: Expression) -> Expression where V.Datatype : Equatable { guard let lhs = lhs else { return "IS".infix(Expression(value: nil), rhs) } - return "=".infix(lhs, rhs) + return Operator.eq.infix(lhs, rhs) } public func !=(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Equatable { - return infix(lhs, rhs) + return Operator.neq.infix(lhs, rhs) } public func !=(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Equatable { - return infix(lhs, rhs) + return Operator.neq.infix(lhs, rhs) } public func !=(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Equatable { - return infix(lhs, rhs) + return Operator.neq.infix(lhs, rhs) } public func !=(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Equatable { - return infix(lhs, rhs) + return Operator.neq.infix(lhs, rhs) } public func !=(lhs: Expression, rhs: V) -> Expression where V.Datatype : Equatable { - return infix(lhs, rhs) + return Operator.neq.infix(lhs, rhs) } public func !=(lhs: Expression, rhs: V?) -> Expression where V.Datatype : Equatable { guard let rhs = rhs else { return "IS NOT".infix(lhs, Expression(value: nil)) } - return infix(lhs, rhs) + return Operator.neq.infix(lhs, rhs) } public func !=(lhs: V, rhs: Expression) -> Expression where V.Datatype : Equatable { - return infix(lhs, rhs) + return Operator.neq.infix(lhs, rhs) } public func !=(lhs: V?, rhs: Expression) -> Expression where V.Datatype : Equatable { guard let lhs = lhs else { return "IS NOT".infix(Expression(value: nil), rhs) } - return infix(lhs, rhs) + return Operator.neq.infix(lhs, rhs) } public func >(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.gt.infix(lhs, rhs) } public func >(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.gt.infix(lhs, rhs) } public func >(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.gt.infix(lhs, rhs) } public func >(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.gt.infix(lhs, rhs) } public func >(lhs: Expression, rhs: V) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.gt.infix(lhs, rhs) } public func >(lhs: Expression, rhs: V) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.gt.infix(lhs, rhs) } public func >(lhs: V, rhs: Expression) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.gt.infix(lhs, rhs) } public func >(lhs: V, rhs: Expression) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.gt.infix(lhs, rhs) } public func >=(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.gte.infix(lhs, rhs) } public func >=(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.gte.infix(lhs, rhs) } public func >=(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.gte.infix(lhs, rhs) } public func >=(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.gte.infix(lhs, rhs) } public func >=(lhs: Expression, rhs: V) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.gte.infix(lhs, rhs) } public func >=(lhs: Expression, rhs: V) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.gte.infix(lhs, rhs) } public func >=(lhs: V, rhs: Expression) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.gte.infix(lhs, rhs) } public func >=(lhs: V, rhs: Expression) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.gte.infix(lhs, rhs) } public func <(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.lt.infix(lhs, rhs) } public func <(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.lt.infix(lhs, rhs) } public func <(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.lt.infix(lhs, rhs) } public func <(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.lt.infix(lhs, rhs) } public func <(lhs: Expression, rhs: V) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.lt.infix(lhs, rhs) } public func <(lhs: Expression, rhs: V) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.lt.infix(lhs, rhs) } public func <(lhs: V, rhs: Expression) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.lt.infix(lhs, rhs) } public func <(lhs: V, rhs: Expression) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.lt.infix(lhs, rhs) } public func <=(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.lte.infix(lhs, rhs) } public func <=(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.lte.infix(lhs, rhs) } public func <=(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.lte.infix(lhs, rhs) } public func <=(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.lte.infix(lhs, rhs) } public func <=(lhs: Expression, rhs: V) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.lte.infix(lhs, rhs) } public func <=(lhs: Expression, rhs: V) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.lte.infix(lhs, rhs) } public func <=(lhs: V, rhs: Expression) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.lte.infix(lhs, rhs) } public func <=(lhs: V, rhs: Expression) -> Expression where V.Datatype : Comparable { - return infix(lhs, rhs) + return Operator.lte.infix(lhs, rhs) } public func ~=(lhs: ClosedRange, rhs: Expression) -> Expression where V.Datatype : Comparable & Value { @@ -517,58 +548,58 @@ public func ~=(lhs: PartialRangeFrom, rhs: Expression) -> Expr // MARK: - public func &&(lhs: Expression, rhs: Expression) -> Expression { - return "AND".infix(lhs, rhs) + return Operator.and.infix(lhs, rhs) } public func &&(lhs: Expression, rhs: Expression) -> Expression { - return "AND".infix(lhs, rhs) + return Operator.and.infix(lhs, rhs) } public func &&(lhs: Expression, rhs: Expression) -> Expression { - return "AND".infix(lhs, rhs) + return Operator.and.infix(lhs, rhs) } public func &&(lhs: Expression, rhs: Expression) -> Expression { - return "AND".infix(lhs, rhs) + return Operator.and.infix(lhs, rhs) } public func &&(lhs: Expression, rhs: Bool) -> Expression { - return "AND".infix(lhs, rhs) + return Operator.and.infix(lhs, rhs) } public func &&(lhs: Expression, rhs: Bool) -> Expression { - return "AND".infix(lhs, rhs) + return Operator.and.infix(lhs, rhs) } public func &&(lhs: Bool, rhs: Expression) -> Expression { - return "AND".infix(lhs, rhs) + return Operator.and.infix(lhs, rhs) } public func &&(lhs: Bool, rhs: Expression) -> Expression { - return "AND".infix(lhs, rhs) + return Operator.and.infix(lhs, rhs) } public func ||(lhs: Expression, rhs: Expression) -> Expression { - return "OR".infix(lhs, rhs) + return Operator.or.infix(lhs, rhs) } public func ||(lhs: Expression, rhs: Expression) -> Expression { - return "OR".infix(lhs, rhs) + return Operator.or.infix(lhs, rhs) } public func ||(lhs: Expression, rhs: Expression) -> Expression { - return "OR".infix(lhs, rhs) + return Operator.or.infix(lhs, rhs) } public func ||(lhs: Expression, rhs: Expression) -> Expression { - return "OR".infix(lhs, rhs) + return Operator.or.infix(lhs, rhs) } public func ||(lhs: Expression, rhs: Bool) -> Expression { - return "OR".infix(lhs, rhs) + return Operator.or.infix(lhs, rhs) } public func ||(lhs: Expression, rhs: Bool) -> Expression { - return "OR".infix(lhs, rhs) + return Operator.or.infix(lhs, rhs) } public func ||(lhs: Bool, rhs: Expression) -> Expression { - return "OR".infix(lhs, rhs) + return Operator.or.infix(lhs, rhs) } public func ||(lhs: Bool, rhs: Expression) -> Expression { - return "OR".infix(lhs, rhs) + return Operator.or.infix(lhs, rhs) } public prefix func !(rhs: Expression) -> Expression { - return "NOT ".wrap(rhs) + return Operator.not.wrap(rhs) } public prefix func !(rhs: Expression) -> Expression { - return "NOT ".wrap(rhs) + return Operator.not.wrap(rhs) }