This commit is contained in:
Gwendal Roué committed 2020-07-11 10:57:24 +02:00
1 parent 813950f832
commit ae41859bbb
5 files changed
+63 -62

No files matched your search

@@ -376,44 +376,23 @@ public struct _SQLExpressionContains: SQLExpression {
let collection: SQLCollection
let isNegated: Bool
/// - precondition: !collection.expressions.isEmpty
init(_ value: SQLExpressible, _ collection: _SQLExpressionsArray, negated: Bool = false) {
// Make it easier for _SQLExpressionVisitor
assert(!collection.expressions.isEmpty)
self.init(
expression: value.sqlExpression,
collection: collection,
isNegated: negated)
}
init(_ value: SQLExpressible, _ collection: SQLRequestProtocol, negated: Bool = false) {
self.init(
expression: value.sqlExpression,
collection: collection,
isNegated: negated)
}
private init(expression: SQLExpression, collection: SQLCollection, isNegated: Bool) {
self.expression = expression
init(_ value: SQLExpressible, _ collection: SQLCollection, negated: Bool = false) {
self.expression = value.sqlExpression
self.collection = collection
self.isNegated = isNegated
self.isNegated = negated
}
/// :nodoc:
public var _negated: SQLExpression {
_SQLExpressionContains(
expression: expression,
collection: collection,
isNegated: !isNegated)
_SQLExpressionContains(expression, collection, negated: !isNegated)
}
/// :nodoc:
public func _qualifiedExpression(with alias: TableAlias) -> SQLExpression {
_SQLExpressionContains(
expression: expression._qualifiedExpression(with: alias),
collection: collection._qualifiedCollection(with: alias),
isNegated: isNegated)
expression._qualifiedExpression(with: alias),
collection._qualifiedCollection(with: alias),
negated: isNegated)
}
/// :nodoc:
+33 -13
View File
@@ -22,7 +22,7 @@ public protocol SQLOrderingTerm: _SQLOrderingTerm { }
// MARK: - _SQLOrdering
/// :nodoc:
public enum _SQLOrdering: SQLOrderingTerm {
public enum _SQLOrdering: SQLOrderingTerm, Refinable {
case asc(SQLExpression)
case desc(SQLExpression)
#if GRDBCUSTOMSQLITE
@@ -30,6 +30,37 @@ public enum _SQLOrdering: SQLOrderingTerm {
case descNullsFirst(SQLExpression)
#endif
var expression: SQLExpression {
get {
switch self {
case .asc(let expression):
return expression
case .desc(let expression):
return expression
#if GRDBCUSTOMSQLITE
case .ascNullsLast(let expression):
return expression
case .descNullsFirst(let expression):
return expression
#endif
}
}
set {
switch self {
case .asc:
self = .asc(newValue)
case .desc:
self = .desc(newValue)
#if GRDBCUSTOMSQLITE
case .ascNullsLast:
self = .ascNullsLast(newValue)
case .descNullsFirst:
self = .descNullsFirst(newValue)
#endif
}
}
}
/// :nodoc:
public var _reversed: SQLOrderingTerm {
switch self {
@@ -48,18 +79,7 @@ public enum _SQLOrdering: SQLOrderingTerm {
/// :nodoc:
public func _qualifiedOrdering(with alias: TableAlias) -> SQLOrderingTerm {
switch self {
case .asc(let expression):
return _SQLOrdering.asc(expression._qualifiedExpression(with: alias))
case .desc(let expression):
return _SQLOrdering.desc(expression._qualifiedExpression(with: alias))
#if GRDBCUSTOMSQLITE
case .ascNullsLast(let expression):
return _SQLOrdering.ascNullsLast(expression._qualifiedExpression(with: alias))
case .descNullsFirst(let expression):
return _SQLOrdering.descNullsFirst(expression._qualifiedExpression(with: alias))
#endif
}
map(\.expression) { $0._qualifiedExpression(with: alias) }
}
/// :nodoc: