-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
338 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import Foundation | ||
|
||
public class BinaryOperator: Expression { | ||
var lhs: Expression | ||
var rhs: Expression | ||
var operatorType: BinaryOperatorType | ||
|
||
init(lhs: Expression, rhs: Expression, operatorType: BinaryOperatorType) { | ||
self.lhs = lhs | ||
self.rhs = rhs | ||
self.operatorType = operatorType | ||
} | ||
} | ||
|
||
extension BinaryOperator: Serializable { | ||
public func serialize(with schemaProvider: SchemaProvider) throws -> String { | ||
let leftString = try self.lhs.serialize(with: schemaProvider) | ||
let rightString = try self.rhs.serialize(with: schemaProvider) | ||
return "\(leftString) \(self.operatorType) \(rightString)" | ||
} | ||
} | ||
|
||
public func equal(lhs: Expression, rhs: Expression) -> BinaryOperator { | ||
return BinaryOperator(lhs: lhs, rhs: rhs, operatorType: .equal) | ||
} | ||
|
||
public func notEqual(lhs: Expression, rhs: Expression) -> BinaryOperator { | ||
return BinaryOperator(lhs: lhs, rhs: rhs, operatorType: .notEqual) | ||
} | ||
|
||
public func lesserThan(lhs: Expression, rhs: Expression) -> BinaryOperator { | ||
return BinaryOperator(lhs: lhs, rhs: rhs, operatorType: .lesserThan) | ||
} | ||
|
||
public func lesserOrEqual(lhs: Expression, rhs: Expression) -> BinaryOperator { | ||
return BinaryOperator(lhs: lhs, rhs: rhs, operatorType: .lesserOrEqual) | ||
} | ||
|
||
public func greaterThan(lhs: Expression, rhs: Expression) -> BinaryOperator { | ||
return BinaryOperator(lhs: lhs, rhs: rhs, operatorType: .greaterThan) | ||
} | ||
|
||
public func greaterOrEqual(lhs: Expression, rhs: Expression) -> BinaryOperator { | ||
return BinaryOperator(lhs: lhs, rhs: rhs, operatorType: .greaterOrEqual) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Foundation | ||
|
||
enum BinaryOperatorType { | ||
// case add | ||
// case sub | ||
// case mul | ||
// case div | ||
case equal | ||
case notEqual | ||
case lesserThan | ||
case lesserOrEqual | ||
case greaterThan | ||
case greaterOrEqual | ||
} | ||
|
||
extension BinaryOperatorType: CustomStringConvertible { | ||
var description: String { | ||
switch self { | ||
case .equal: return "==" | ||
case .notEqual: return "!=" | ||
case .lesserThan: return "<" | ||
case .greaterThan: return ">" | ||
case .lesserOrEqual: return "<=" | ||
case .greaterOrEqual: return ">=" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Foundation | ||
|
||
public protocol SelectConstraint: Serializable { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Foundation | ||
|
||
public class Where: SelectConstraint { | ||
var expression: Expression | ||
|
||
init(expression: Expression) { | ||
self.expression = expression | ||
} | ||
} | ||
|
||
extension Where: Serializable { | ||
public func serialize(with schemaProvider: SchemaProvider) throws -> String { | ||
let expressionString = try self.expression.serialize(with: schemaProvider) | ||
return "WHERE \(expressionString)" | ||
} | ||
} | ||
|
||
public func where_(_ expression: Expression) -> Where { | ||
return Where(expression: expression) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import Foundation | ||
|
||
public protocol Serializable { | ||
func serialize(with schemaProvider: SchemaProvider) throws -> String | ||
} | ||
|
||
extension Int: Serializable { | ||
public func serialize(with schemaProvider: SchemaProvider) throws -> String { | ||
return self.description | ||
} | ||
} | ||
|
||
extension Bool: Serializable { | ||
public func serialize(with schemaProvider: SchemaProvider) throws -> String { | ||
return self ? "1" : "0" | ||
} | ||
} | ||
|
||
extension String: Serializable { | ||
public func serialize(with schemaProvider: SchemaProvider) throws -> String { | ||
return "'\(self)'" | ||
} | ||
} | ||
|
||
extension KeyPath: Serializable { | ||
public func serialize(with schemaProvider: SchemaProvider) throws -> String { | ||
return try schemaProvider.columnNameWithTable(keyPath: self) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.