Simplify handling of collated expressions

This commit is contained in:
Gwendal Roué committed 2021-03-27 16:34:37 +01:00
1 parent fcff9b34ba
commit c4f9ddd688
10 files changed
+64 -346

No files matched your search

-182
View File
@@ -13,19 +13,6 @@ public func == (lhs: SQLSpecificExpressible, rhs: SQLExpressible?) -> SQLExpress
.equal(lhs.sqlExpression, rhs?.sqlExpression ?? .null)
}
/// An SQL expression that compares two expressions with the `=` SQL operator.
///
/// // name = 'Arthur' COLLATE NOCASE
/// Column("name").collating(.nocase) == "Arthur"
///
/// When the right operand is nil, `IS NULL` is used instead.
///
/// // name IS NULL
/// Column("name").collating(.nocase) == nil
public func == (lhs: SQLCollatedExpression, rhs: SQLExpressible?) -> SQLExpression {
.collated(lhs.expression == rhs, lhs.collationName)
}
/// An SQL expression that checks the boolean value of an expression.
///
/// The comparison is done with the built-in boolean evaluation of SQLite:
@@ -56,19 +43,6 @@ public func == (lhs: SQLExpressible?, rhs: SQLSpecificExpressible) -> SQLExpress
.equal(lhs?.sqlExpression ?? .null, rhs.sqlExpression)
}
/// An SQL expression that compares two expressions with the `=` SQL operator.
///
/// // 'Arthur' = name COLLATE NOCASE
/// "Arthur" == Column("name").collating(.nocase)
///
/// When the left operand is nil, `IS NULL` is used instead.
///
/// // name IS NULL
/// nil == Column("name").collating(.nocase)
public func == (lhs: SQLExpressible?, rhs: SQLCollatedExpression) -> SQLExpression {
.collated(lhs == rhs.expression, rhs.collationName)
}
/// An SQL expression that checks the boolean value of an expression.
///
/// The comparison is done with the built-in boolean evaluation of SQLite:
@@ -107,19 +81,6 @@ public func != (lhs: SQLSpecificExpressible, rhs: SQLExpressible?) -> SQLExpress
!(lhs == rhs)
}
/// An SQL expression that compares two expressions with the `<>` SQL operator.
///
/// // name <> 'Arthur' COLLATE NOCASE
/// Column("name").collating(.nocase) != "Arthur"
///
/// When the right operand is nil, `IS NOT NULL` is used instead.
///
/// // name IS NOT NULL
/// Column("name").collating(.nocase) != nil
public func != (lhs: SQLCollatedExpression, rhs: SQLExpressible?) -> SQLExpression {
!(lhs == rhs)
}
/// An SQL expression that checks the boolean value of an expression.
///
/// The comparison is done with the built-in boolean evaluation of SQLite:
@@ -146,19 +107,6 @@ public func != (lhs: SQLExpressible?, rhs: SQLSpecificExpressible) -> SQLExpress
!(lhs == rhs)
}
/// An SQL expression that compares two expressions with the `<>` SQL operator.
///
/// // 'Arthur' <> name COLLATE NOCASE
/// "Arthur" != Column("name").collating(.nocase)
///
/// When the left operand is nil, `IS NOT NULL` is used instead.
///
/// // name IS NOT NULL
/// nil != Column("name").collating(.nocase)
public func != (lhs: SQLExpressible?, rhs: SQLCollatedExpression) -> SQLExpression {
!(lhs == rhs)
}
/// An SQL expression that checks the boolean value of an expression.
///
/// The comparison is done with the built-in boolean evaluation of SQLite:
@@ -188,14 +136,6 @@ public func === (lhs: SQLSpecificExpressible, rhs: SQLExpressible?) -> SQLExpres
.compare(.is, lhs.sqlExpression, rhs?.sqlExpression ?? .null)
}
/// An SQL expression that compares two expressions with the `IS` SQL operator.
///
/// // name IS 'Arthur' COLLATE NOCASE
/// Column("name").collating(.nocase) === "Arthur"
public func === (lhs: SQLCollatedExpression, rhs: SQLExpressible?) -> SQLExpression {
.collated(lhs.expression === rhs, lhs.collationName)
}
/// An SQL expression that compares two expressions with the `IS` SQL operator.
///
/// // name IS 'Arthur'
@@ -208,14 +148,6 @@ public func === (lhs: SQLExpressible?, rhs: SQLSpecificExpressible) -> SQLExpres
}
}
/// An SQL expression that compares two expressions with the `IS` SQL operator.
///
/// // name IS 'Arthur' COLLATE NOCASE
/// "Arthur" === Column("name").collating(.nocase)
public func === (lhs: SQLExpressible?, rhs: SQLCollatedExpression) -> SQLExpression {
.collated(lhs === rhs.expression, rhs.collationName)
}
/// An SQL expression that compares two expressions with the `IS` SQL operator.
///
/// // email IS login
@@ -232,14 +164,6 @@ public func !== (lhs: SQLSpecificExpressible, rhs: SQLExpressible?) -> SQLExpres
!(lhs === rhs)
}
/// An SQL expression that compares two expressions with the `IS NOT` SQL operator.
///
/// // name IS NOT 'Arthur' COLLATE NOCASE
/// Column("name").collating(.nocase) !== "Arthur"
public func !== (lhs: SQLCollatedExpression, rhs: SQLExpressible?) -> SQLExpression {
!(lhs === rhs)
}
/// An SQL expression that compares two expressions with the `IS NOT` SQL operator.
///
/// // name IS NOT 'Arthur'
@@ -248,14 +172,6 @@ public func !== (lhs: SQLExpressible?, rhs: SQLSpecificExpressible) -> SQLExpres
!(lhs === rhs)
}
/// An SQL expression that compares two expressions with the `IS NOT` SQL operator.
///
/// // name IS NOT 'Arthur' COLLATE NOCASE
/// "Arthur" !== Column("name").collating(.nocase)
public func !== (lhs: SQLExpressible?, rhs: SQLCollatedExpression) -> SQLExpression {
!(lhs === rhs)
}
/// An SQL expression that compares two expressions with the `IS NOT` SQL operator.
///
/// // email IS NOT login
@@ -274,14 +190,6 @@ public func < (lhs: SQLSpecificExpressible, rhs: SQLExpressible) -> SQLExpressio
.binary(.lessThan, lhs.sqlExpression, rhs.sqlExpression)
}
/// An SQL expression that compares two expressions with the `<` SQL operator.
///
/// // name < 'Arthur' COLLATE NOCASE
/// Column("name").collating(.nocase) < "Arthur"
public func < (lhs: SQLCollatedExpression, rhs: SQLExpressible) -> SQLExpression {
.collated(lhs.expression < rhs, lhs.collationName)
}
/// An SQL expression that compares two expressions with the `<` SQL operator.
///
/// // 18 < score
@@ -290,14 +198,6 @@ public func < (lhs: SQLExpressible, rhs: SQLSpecificExpressible) -> SQLExpressio
.binary(.lessThan, lhs.sqlExpression, rhs.sqlExpression)
}
/// An SQL expression that compares two expressions with the `<` SQL operator.
///
/// // 'Arthur' < name COLLATE NOCASE
/// "Arthur" < Column("name").collating(.nocase)
public func < (lhs: SQLExpressible, rhs: SQLCollatedExpression) -> SQLExpression {
.collated(lhs < rhs.expression, rhs.collationName)
}
/// An SQL expression that compares two expressions with the `<` SQL operator.
///
/// // width < height
@@ -314,14 +214,6 @@ public func <= (lhs: SQLSpecificExpressible, rhs: SQLExpressible) -> SQLExpressi
.binary(.lessThanOrEqual, lhs.sqlExpression, rhs.sqlExpression)
}
/// An SQL expression that compares two expressions with the `<=` SQL operator.
///
/// // name <= 'Arthur' COLLATE NOCASE
/// Column("name").collating(.nocase) <= "Arthur"
public func <= (lhs: SQLCollatedExpression, rhs: SQLExpressible) -> SQLExpression {
.collated(lhs.expression <= rhs, lhs.collationName)
}
/// An SQL expression that compares two expressions with the `<=` SQL operator.
///
/// // 18 <= score
@@ -330,14 +222,6 @@ public func <= (lhs: SQLExpressible, rhs: SQLSpecificExpressible) -> SQLExpressi
.binary(.lessThanOrEqual, lhs.sqlExpression, rhs.sqlExpression)
}
/// An SQL expression that compares two expressions with the `<=` SQL operator.
///
/// // 'Arthur' <= name COLLATE NOCASE
/// "Arthur" <= Column("name").collating(.nocase)
public func <= (lhs: SQLExpressible, rhs: SQLCollatedExpression) -> SQLExpression {
.collated(lhs <= rhs.expression, rhs.collationName)
}
/// An SQL expression that compares two expressions with the `<=` SQL operator.
///
/// // width <= height
@@ -354,14 +238,6 @@ public func > (lhs: SQLSpecificExpressible, rhs: SQLExpressible) -> SQLExpressio
.binary(.greaterThan, lhs.sqlExpression, rhs.sqlExpression)
}
/// An SQL expression that compares two expressions with the `>` SQL operator.
///
/// // name > 'Arthur' COLLATE NOCASE
/// Column("name").collating(.nocase) > "Arthur"
public func > (lhs: SQLCollatedExpression, rhs: SQLExpressible) -> SQLExpression {
.collated(lhs.expression > rhs, lhs.collationName)
}
/// An SQL expression that compares two expressions with the `>` SQL operator.
///
/// // 18 > score
@@ -370,14 +246,6 @@ public func > (lhs: SQLExpressible, rhs: SQLSpecificExpressible) -> SQLExpressio
.binary(.greaterThan, lhs.sqlExpression, rhs.sqlExpression)
}
/// An SQL expression that compares two expressions with the `>` SQL operator.
///
/// // 'Arthur' > name COLLATE NOCASE
/// "Arthur" > Column("name").collating(.nocase)
public func > (lhs: SQLExpressible, rhs: SQLCollatedExpression) -> SQLExpression {
.collated(lhs > rhs.expression, rhs.collationName)
}
/// An SQL expression that compares two expressions with the `>` SQL operator.
///
/// // width > height
@@ -394,14 +262,6 @@ public func >= (lhs: SQLSpecificExpressible, rhs: SQLExpressible) -> SQLExpressi
.binary(.greaterThanOrEqual, lhs.sqlExpression, rhs.sqlExpression)
}
/// An SQL expression that compares two expressions with the `>=` SQL operator.
///
/// // name >= 'Arthur' COLLATE NOCASE
/// Column("name").collating(.nocase) >= "Arthur"
public func >= (lhs: SQLCollatedExpression, rhs: SQLExpressible) -> SQLExpression {
.collated(lhs.expression >= rhs, lhs.collationName)
}
/// An SQL expression that compares two expressions with the `>=` SQL operator.
///
/// // 18 >= score
@@ -410,14 +270,6 @@ public func >= (lhs: SQLExpressible, rhs: SQLSpecificExpressible) -> SQLExpressi
.binary(.greaterThanOrEqual, lhs.sqlExpression, rhs.sqlExpression)
}
/// An SQL expression that compares two expressions with the `>=` SQL operator.
///
/// // 'Arthur' >= name COLLATE NOCASE
/// "Arthur" >= Column("name").collating(.nocase)
public func >= (lhs: SQLExpressible, rhs: SQLCollatedExpression) -> SQLExpression {
.collated(lhs >= rhs.expression, rhs.collationName)
}
/// An SQL expression that compares two expressions with the `>=` SQL operator.
///
/// // width >= height
@@ -436,14 +288,6 @@ extension Range where Bound: SQLExpressible {
public func contains(_ element: SQLSpecificExpressible) -> SQLExpression {
(element >= lowerBound) && (element < upperBound)
}
/// An SQL expression that checks the inclusion of an expression in a range.
///
/// // email >= 'A' COLLATE NOCASE AND email < 'B' COLLATE NOCASE
/// ("A"..<"B").contains(Column("email").collating(.nocase))
public func contains(_ element: SQLCollatedExpression) -> SQLExpression {
(element >= lowerBound) && (element < upperBound)
}
}
extension ClosedRange where Bound: SQLExpressible {
@@ -457,14 +301,6 @@ extension ClosedRange where Bound: SQLExpressible {
lowerBound: lowerBound.sqlExpression,
upperBound: upperBound.sqlExpression)
}
/// An SQL expression that checks the inclusion of an expression in a range.
///
/// // email BETWEEN 'A' AND 'B' COLLATE NOCASE
/// ("A"..."B").contains(Column("email").collating(.nocase))
public func contains(_ element: SQLCollatedExpression) -> SQLExpression {
.collated(contains(element.expression), element.collationName)
}
}
extension CountableRange where Bound: SQLExpressible {
@@ -499,15 +335,6 @@ extension Sequence where Self.Iterator.Element: SQLExpressible {
public func contains(_ element: SQLSpecificExpressible) -> SQLExpression {
SQLCollection.array(map(\.sqlExpression)).contains(element.sqlExpression)
}
/// An SQL expression that checks the inclusion of an expression in
/// a sequence.
///
/// // (name COLLATE NOCASE) IN ('A', 'B')
/// ["A", "B"].contains(Column("name").collating(.nocase))
public func contains(_ element: SQLCollatedExpression) -> SQLExpression {
SQLCollection.array(map(\.sqlExpression)).contains(element.sqlExpression)
}
}
extension Sequence where Self.Iterator.Element == SQLExpressible {
@@ -519,15 +346,6 @@ extension Sequence where Self.Iterator.Element == SQLExpressible {
public func contains(_ element: SQLSpecificExpressible) -> SQLExpression {
SQLCollection.array(map(\.sqlExpression)).contains(element.sqlExpression)
}
/// An SQL expression that checks the inclusion of an expression in
/// a sequence.
///
/// // (name COLLATE NOCASE) IN ('A', 'B')
/// ["A", "B"].contains(Column("name").collating(.nocase))
public func contains(_ element: SQLCollatedExpression) -> SQLExpression {
SQLCollection.array(map(\.sqlExpression)).contains(element.sqlExpression)
}
}