mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-29 04:24:21 +00:00
Merge branch 'master' of github.com:groue/GRDB.swift into Swift3
Conflicts: GRDB/QueryInterface/QueryInterfaceRequest.swift GRDB/QueryInterface/SQLCollation.swift GRDB/QueryInterface/SQLFunction.swift GRDB/QueryInterface/SQLOperator.swift GRDB/QueryInterface/SQLSelectQuery.swift GRDB/QueryInterface/SQLTableBuilder.swift
This commit is contained in:
commit
2c3bf06740
7 files changed
+121
-100
No files matched your search
@@ -1,3 +1,32 @@
|
||||
// MARK: - SQLExpressible
|
||||
|
||||
/// This protocol is an implementation detail of the query interface.
|
||||
/// Do not use it directly.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#the-query-interface
|
||||
public protocol _SQLExpressible {
|
||||
|
||||
/// This property is an implementation detail of the query interface.
|
||||
/// Do not use it directly.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#the-query-interface
|
||||
var sqlExpression: _SQLExpression { get }
|
||||
}
|
||||
|
||||
/// The protocol for all types that can be turned into an SQL expression.
|
||||
///
|
||||
/// It is adopted by protocols like DatabaseValueConvertible, and types
|
||||
/// like Column.
|
||||
///
|
||||
/// Do not declare adoption of SQLExpressible on any type: you would have to
|
||||
/// use semi-private APIs and types, whose name start with an underscore, that
|
||||
/// are subject to change as GRDB evolves.
|
||||
public protocol SQLExpressible : _SQLExpressible {
|
||||
}
|
||||
|
||||
|
||||
// MARK: - DatabaseValueConvertible
|
||||
|
||||
/// Types that adopt DatabaseValueConvertible can be initialized from
|
||||
/// database values.
|
||||
///
|
||||
@@ -14,7 +43,7 @@
|
||||
/// String.fetchOne(statement, arguments:...) // String?
|
||||
///
|
||||
/// DatabaseValueConvertible is adopted by Bool, Int, String, etc.
|
||||
public protocol DatabaseValueConvertible : _SQLExpressible {
|
||||
public protocol DatabaseValueConvertible : SQLExpressible {
|
||||
/// Returns a value that can be stored in the database.
|
||||
var databaseValue: DatabaseValue { get }
|
||||
|
||||
@@ -23,6 +52,19 @@ public protocol DatabaseValueConvertible : _SQLExpressible {
|
||||
}
|
||||
|
||||
|
||||
// SQLExpressible adoption
|
||||
extension DatabaseValueConvertible {
|
||||
|
||||
/// This property is an implementation detail of the query interface.
|
||||
/// Do not use it directly.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#the-query-interface
|
||||
public var sqlExpression: _SQLExpression {
|
||||
return .value(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// DatabaseValueConvertible comes with built-in methods that allow to fetch
|
||||
/// sequences, arrays, or single values:
|
||||
///
|
||||
|
||||
@@ -112,7 +112,7 @@ extension QueryInterfaceRequest {
|
||||
|
||||
/// Returns a new QueryInterfaceRequest with the provided *predicate* added to the
|
||||
/// eventual set of already applied predicates.
|
||||
public func filter(_ predicate: _SQLExpressible) -> QueryInterfaceRequest<T> {
|
||||
public func filter(_ predicate: SQLExpressible) -> QueryInterfaceRequest<T> {
|
||||
var query = self.query
|
||||
if let whereExpression = query.whereExpression {
|
||||
query.whereExpression = .infixOperator("AND", whereExpression, predicate.sqlExpression)
|
||||
@@ -129,12 +129,12 @@ extension QueryInterfaceRequest {
|
||||
}
|
||||
|
||||
/// Returns a new QueryInterfaceRequest grouped according to *expressions*.
|
||||
public func group(_ expressions: _SQLExpressible...) -> QueryInterfaceRequest<T> {
|
||||
public func group(_ expressions: SQLExpressible...) -> QueryInterfaceRequest<T> {
|
||||
return group(expressions)
|
||||
}
|
||||
|
||||
/// Returns a new QueryInterfaceRequest grouped according to *expressions*.
|
||||
public func group(_ expressions: [_SQLExpressible]) -> QueryInterfaceRequest<T> {
|
||||
public func group(_ expressions: [SQLExpressible]) -> QueryInterfaceRequest<T> {
|
||||
var query = self.query
|
||||
query.groupByExpressions = expressions.map { $0.sqlExpression }
|
||||
return QueryInterfaceRequest(query: query)
|
||||
@@ -147,7 +147,7 @@ extension QueryInterfaceRequest {
|
||||
|
||||
/// Returns a new QueryInterfaceRequest with the provided *predicate* added to the
|
||||
/// eventual set of already applied predicates.
|
||||
public func having(_ predicate: _SQLExpressible) -> QueryInterfaceRequest<T> {
|
||||
public func having(_ predicate: SQLExpressible) -> QueryInterfaceRequest<T> {
|
||||
var query = self.query
|
||||
if let havingExpression = query.havingExpression {
|
||||
query.havingExpression = (havingExpression && predicate).sqlExpression
|
||||
@@ -219,7 +219,7 @@ extension QueryInterfaceRequest {
|
||||
|
||||
/// Returns an SQL expression that checks the inclusion of a value in
|
||||
/// the results of another request.
|
||||
public func contains(_ element: _SQLExpressible) -> _SQLExpression {
|
||||
public func contains(_ element: SQLExpressible) -> _SQLExpression {
|
||||
return .inSubQuery(query, element.sqlExpression)
|
||||
}
|
||||
|
||||
@@ -256,7 +256,7 @@ extension TableMapping {
|
||||
}
|
||||
|
||||
/// Returns a QueryInterfaceRequest with the provided *predicate*.
|
||||
public static func filter(_ predicate: _SQLExpressible) -> QueryInterfaceRequest<Self> {
|
||||
public static func filter(_ predicate: SQLExpressible) -> QueryInterfaceRequest<Self> {
|
||||
return all().filter(predicate)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ public struct _SQLCollatedExpression {
|
||||
let collationName: String
|
||||
}
|
||||
|
||||
extension _SQLCollatedExpression : _SQLExpressible {
|
||||
extension _SQLCollatedExpression : SQLExpressible {
|
||||
|
||||
/// This property is an implementation detail of the query interface.
|
||||
/// Do not use it directly.
|
||||
@@ -80,14 +80,14 @@ extension _SpecificSQLExpressible {
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func == (lhs: _SQLCollatedExpression, rhs: _SQLExpressible?) -> _SQLExpression {
|
||||
public func == (lhs: _SQLCollatedExpression, rhs: SQLExpressible?) -> _SQLExpression {
|
||||
return .collate(lhs.baseExpression == rhs, lhs.collationName)
|
||||
}
|
||||
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func == (lhs: _SQLExpressible?, rhs: _SQLCollatedExpression) -> _SQLExpression {
|
||||
public func == (lhs: SQLExpressible?, rhs: _SQLCollatedExpression) -> _SQLExpression {
|
||||
return .collate(lhs == rhs.baseExpression, rhs.collationName)
|
||||
}
|
||||
|
||||
@@ -97,14 +97,14 @@ public func == (lhs: _SQLExpressible?, rhs: _SQLCollatedExpression) -> _SQLExpre
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func != (lhs: _SQLCollatedExpression, rhs: _SQLExpressible?) -> _SQLExpression {
|
||||
public func != (lhs: _SQLCollatedExpression, rhs: SQLExpressible?) -> _SQLExpression {
|
||||
return .collate(lhs.baseExpression != rhs, lhs.collationName)
|
||||
}
|
||||
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func != (lhs: _SQLExpressible?, rhs: _SQLCollatedExpression) -> _SQLExpression {
|
||||
public func != (lhs: SQLExpressible?, rhs: _SQLCollatedExpression) -> _SQLExpression {
|
||||
return .collate(lhs != rhs.baseExpression, rhs.collationName)
|
||||
}
|
||||
|
||||
@@ -114,14 +114,14 @@ public func != (lhs: _SQLExpressible?, rhs: _SQLCollatedExpression) -> _SQLExpre
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func < (lhs: _SQLCollatedExpression, rhs: _SQLExpressible) -> _SQLExpression {
|
||||
public func < (lhs: _SQLCollatedExpression, rhs: SQLExpressible) -> _SQLExpression {
|
||||
return .collate(lhs.baseExpression < rhs, lhs.collationName)
|
||||
}
|
||||
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func < (lhs: _SQLExpressible, rhs: _SQLCollatedExpression) -> _SQLExpression {
|
||||
public func < (lhs: SQLExpressible, rhs: _SQLCollatedExpression) -> _SQLExpression {
|
||||
return .collate(lhs < rhs.baseExpression, rhs.collationName)
|
||||
}
|
||||
|
||||
@@ -131,14 +131,14 @@ public func < (lhs: _SQLExpressible, rhs: _SQLCollatedExpression) -> _SQLExpress
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func <= (lhs: _SQLCollatedExpression, rhs: _SQLExpressible) -> _SQLExpression {
|
||||
public func <= (lhs: _SQLCollatedExpression, rhs: SQLExpressible) -> _SQLExpression {
|
||||
return .collate(lhs.baseExpression <= rhs, lhs.collationName)
|
||||
}
|
||||
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func <= (lhs: _SQLExpressible, rhs: _SQLCollatedExpression) -> _SQLExpression {
|
||||
public func <= (lhs: SQLExpressible, rhs: _SQLCollatedExpression) -> _SQLExpression {
|
||||
return .collate(lhs <= rhs.baseExpression, rhs.collationName)
|
||||
}
|
||||
|
||||
@@ -148,14 +148,14 @@ public func <= (lhs: _SQLExpressible, rhs: _SQLCollatedExpression) -> _SQLExpres
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func > (lhs: _SQLCollatedExpression, rhs: _SQLExpressible) -> _SQLExpression {
|
||||
public func > (lhs: _SQLCollatedExpression, rhs: SQLExpressible) -> _SQLExpression {
|
||||
return .collate(lhs.baseExpression > rhs, lhs.collationName)
|
||||
}
|
||||
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func > (lhs: _SQLExpressible, rhs: _SQLCollatedExpression) -> _SQLExpression {
|
||||
public func > (lhs: SQLExpressible, rhs: _SQLCollatedExpression) -> _SQLExpression {
|
||||
return .collate(lhs > rhs.baseExpression, rhs.collationName)
|
||||
}
|
||||
|
||||
@@ -165,21 +165,21 @@ public func > (lhs: _SQLExpressible, rhs: _SQLCollatedExpression) -> _SQLExpress
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func >= (lhs: _SQLCollatedExpression, rhs: _SQLExpressible) -> _SQLExpression {
|
||||
public func >= (lhs: _SQLCollatedExpression, rhs: SQLExpressible) -> _SQLExpression {
|
||||
return .collate(lhs.baseExpression >= rhs, lhs.collationName)
|
||||
}
|
||||
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func >= (lhs: _SQLExpressible, rhs: _SQLCollatedExpression) -> _SQLExpression {
|
||||
public func >= (lhs: SQLExpressible, rhs: _SQLCollatedExpression) -> _SQLExpression {
|
||||
return .collate(lhs >= rhs.baseExpression, rhs.collationName)
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Operator BETWEEN COLLATE
|
||||
|
||||
extension Range where Bound: _SQLExpressible {
|
||||
extension Range where Bound: SQLExpressible {
|
||||
/// Returns an SQL expression that compares the inclusion of a value in
|
||||
/// a range.
|
||||
///
|
||||
@@ -189,7 +189,7 @@ extension Range where Bound: _SQLExpressible {
|
||||
}
|
||||
}
|
||||
|
||||
extension ClosedRange where Bound: _SQLExpressible {
|
||||
extension ClosedRange where Bound: SQLExpressible {
|
||||
/// Returns an SQL expression that compares the inclusion of a value in
|
||||
/// a range.
|
||||
///
|
||||
@@ -202,7 +202,7 @@ extension ClosedRange where Bound: _SQLExpressible {
|
||||
|
||||
// MARK: - Operator IN COLLATE
|
||||
|
||||
extension Sequence where Self.Iterator.Element: _SQLExpressible {
|
||||
extension Sequence where Self.Iterator.Element: SQLExpressible {
|
||||
/// Returns an SQL expression that compares the inclusion of a value in
|
||||
/// a sequence.
|
||||
///
|
||||
@@ -218,14 +218,14 @@ extension Sequence where Self.Iterator.Element: _SQLExpressible {
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func === (lhs: _SQLCollatedExpression, rhs: _SQLExpressible?) -> _SQLExpression {
|
||||
public func === (lhs: _SQLCollatedExpression, rhs: SQLExpressible?) -> _SQLExpression {
|
||||
return .collate(lhs.baseExpression === rhs, lhs.collationName)
|
||||
}
|
||||
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func === (lhs: _SQLExpressible?, rhs: _SQLCollatedExpression) -> _SQLExpression {
|
||||
public func === (lhs: SQLExpressible?, rhs: _SQLCollatedExpression) -> _SQLExpression {
|
||||
return .collate(lhs == rhs.baseExpression, rhs.collationName)
|
||||
}
|
||||
|
||||
@@ -235,13 +235,13 @@ public func === (lhs: _SQLExpressible?, rhs: _SQLCollatedExpression) -> _SQLExpr
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func !== (lhs: _SQLCollatedExpression, rhs: _SQLExpressible?) -> _SQLExpression {
|
||||
public func !== (lhs: _SQLCollatedExpression, rhs: SQLExpressible?) -> _SQLExpression {
|
||||
return .collate(lhs.baseExpression !== rhs, lhs.collationName)
|
||||
}
|
||||
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func !== (lhs: _SQLExpressible?, rhs: _SQLCollatedExpression) -> _SQLExpression {
|
||||
public func !== (lhs: SQLExpressible?, rhs: _SQLCollatedExpression) -> _SQLExpression {
|
||||
return .collate(lhs !== rhs.baseExpression, rhs.collationName)
|
||||
}
|
||||
@@ -4,7 +4,7 @@ extension DatabaseFunction {
|
||||
/// Returns an SQL expression that applies the function.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-functions
|
||||
public func apply(_ arguments: _SQLExpressible...) -> _SQLExpression {
|
||||
public func apply(_ arguments: SQLExpressible...) -> _SQLExpression {
|
||||
return .function(name, arguments.map { $0.sqlExpression })
|
||||
}
|
||||
}
|
||||
@@ -55,14 +55,14 @@ public func count(distinct value: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
/// Returns an SQL expression.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-functions
|
||||
public func ?? (lhs: _SpecificSQLExpressible, rhs: _SQLExpressible) -> _SQLExpression {
|
||||
public func ?? (lhs: _SpecificSQLExpressible, rhs: SQLExpressible) -> _SQLExpression {
|
||||
return .function("IFNULL", [lhs.sqlExpression, rhs.sqlExpression])
|
||||
}
|
||||
|
||||
/// Returns an SQL expression.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-functions
|
||||
public func ?? (lhs: _SQLExpressible?, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
public func ?? (lhs: SQLExpressible?, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
if let lhs = lhs {
|
||||
return .function("IFNULL", [lhs.sqlExpression, rhs.sqlExpression])
|
||||
} else {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func == (lhs: _SpecificSQLExpressible, rhs: _SQLExpressible?) -> _SQLExpression {
|
||||
public func == (lhs: _SpecificSQLExpressible, rhs: SQLExpressible?) -> _SQLExpression {
|
||||
return .equalOperator(lhs.sqlExpression, rhs?.sqlExpression ?? .value(nil))
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public func == (lhs: _SpecificSQLExpressible, rhs: Bool?) -> _SQLExpression {
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func == (lhs: _SQLExpressible?, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
public func == (lhs: SQLExpressible?, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
return .equalOperator(lhs?.sqlExpression ?? .value(nil), rhs.sqlExpression)
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public func == (lhs: _SpecificSQLExpressible, rhs: _SpecificSQLExpressible) -> _
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func != (lhs: _SpecificSQLExpressible, rhs: _SQLExpressible?) -> _SQLExpression {
|
||||
public func != (lhs: _SpecificSQLExpressible, rhs: SQLExpressible?) -> _SQLExpression {
|
||||
return .notEqualOperator(lhs.sqlExpression, rhs?.sqlExpression ?? .value(nil))
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public func != (lhs: _SpecificSQLExpressible, rhs: Bool?) -> _SQLExpression {
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func != (lhs: _SQLExpressible?, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
public func != (lhs: SQLExpressible?, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
return .notEqualOperator(lhs?.sqlExpression ?? .value(nil), rhs.sqlExpression)
|
||||
}
|
||||
|
||||
@@ -111,14 +111,14 @@ public func != (lhs: _SpecificSQLExpressible, rhs: _SpecificSQLExpressible) -> _
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func < (lhs: _SpecificSQLExpressible, rhs: _SQLExpressible) -> _SQLExpression {
|
||||
public func < (lhs: _SpecificSQLExpressible, rhs: SQLExpressible) -> _SQLExpression {
|
||||
return .infixOperator("<", lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func < (lhs: _SQLExpressible, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
public func < (lhs: SQLExpressible, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
return .infixOperator("<", lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
@@ -135,14 +135,14 @@ public func < (lhs: _SpecificSQLExpressible, rhs: _SpecificSQLExpressible) -> _S
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func <= (lhs: _SpecificSQLExpressible, rhs: _SQLExpressible) -> _SQLExpression {
|
||||
public func <= (lhs: _SpecificSQLExpressible, rhs: SQLExpressible) -> _SQLExpression {
|
||||
return .infixOperator("<=", lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func <= (lhs: _SQLExpressible, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
public func <= (lhs: SQLExpressible, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
return .infixOperator("<=", lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
@@ -159,14 +159,14 @@ public func <= (lhs: _SpecificSQLExpressible, rhs: _SpecificSQLExpressible) -> _
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func > (lhs: _SpecificSQLExpressible, rhs: _SQLExpressible) -> _SQLExpression {
|
||||
public func > (lhs: _SpecificSQLExpressible, rhs: SQLExpressible) -> _SQLExpression {
|
||||
return .infixOperator(">", lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func > (lhs: _SQLExpressible, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
public func > (lhs: SQLExpressible, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
return .infixOperator(">", lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
@@ -183,14 +183,14 @@ public func > (lhs: _SpecificSQLExpressible, rhs: _SpecificSQLExpressible) -> _S
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func >= (lhs: _SpecificSQLExpressible, rhs: _SQLExpressible) -> _SQLExpression {
|
||||
public func >= (lhs: _SpecificSQLExpressible, rhs: SQLExpressible) -> _SQLExpression {
|
||||
return .infixOperator(">=", lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func >= (lhs: _SQLExpressible, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
public func >= (lhs: SQLExpressible, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
return .infixOperator(">=", lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
@@ -207,14 +207,14 @@ public func >= (lhs: _SpecificSQLExpressible, rhs: _SpecificSQLExpressible) -> _
|
||||
/// Returns an SQL arithmetic expression.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func * (lhs: _SpecificSQLExpressible, rhs: _SQLExpressible) -> _SQLExpression {
|
||||
public func * (lhs: _SpecificSQLExpressible, rhs: SQLExpressible) -> _SQLExpression {
|
||||
return .infixOperator("*", lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// Returns an SQL arithmetic expression.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func * (lhs: _SQLExpressible, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
public func * (lhs: SQLExpressible, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
return .infixOperator("*", lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
@@ -231,14 +231,14 @@ public func * (lhs: _SpecificSQLExpressible, rhs: _SpecificSQLExpressible) -> _S
|
||||
/// Returns an SQL arithmetic expression.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func / (lhs: _SpecificSQLExpressible, rhs: _SQLExpressible) -> _SQLExpression {
|
||||
public func / (lhs: _SpecificSQLExpressible, rhs: SQLExpressible) -> _SQLExpression {
|
||||
return .infixOperator("/", lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// Returns an SQL arithmetic expression.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func / (lhs: _SQLExpressible, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
public func / (lhs: SQLExpressible, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
return .infixOperator("/", lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
@@ -255,14 +255,14 @@ public func / (lhs: _SpecificSQLExpressible, rhs: _SpecificSQLExpressible) -> _S
|
||||
/// Returns an SQL arithmetic expression.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func + (lhs: _SpecificSQLExpressible, rhs: _SQLExpressible) -> _SQLExpression {
|
||||
public func + (lhs: _SpecificSQLExpressible, rhs: SQLExpressible) -> _SQLExpression {
|
||||
return .infixOperator("+", lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// Returns an SQL arithmetic expression.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func + (lhs: _SQLExpressible, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
public func + (lhs: SQLExpressible, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
return .infixOperator("+", lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
@@ -289,14 +289,14 @@ public prefix func - (value: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
/// Returns an SQL arithmetic expression.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func - (lhs: _SpecificSQLExpressible, rhs: _SQLExpressible) -> _SQLExpression {
|
||||
public func - (lhs: _SpecificSQLExpressible, rhs: SQLExpressible) -> _SQLExpression {
|
||||
return .infixOperator("-", lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// Returns an SQL arithmetic expression.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func - (lhs: _SQLExpressible, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
public func - (lhs: SQLExpressible, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
return .infixOperator("-", lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
@@ -313,14 +313,14 @@ public func - (lhs: _SpecificSQLExpressible, rhs: _SpecificSQLExpressible) -> _S
|
||||
/// Returns an SQL logical expression.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func && (lhs: _SpecificSQLExpressible, rhs: _SQLExpressible) -> _SQLExpression {
|
||||
public func && (lhs: _SpecificSQLExpressible, rhs: SQLExpressible) -> _SQLExpression {
|
||||
return .infixOperator("AND", lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// Returns an SQL logical expression.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func && (lhs: _SQLExpressible, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
public func && (lhs: SQLExpressible, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
return .infixOperator("AND", lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
@@ -334,8 +334,8 @@ public func && (lhs: _SpecificSQLExpressible, rhs: _SpecificSQLExpressible) -> _
|
||||
|
||||
// MARK: - Operator BETWEEN
|
||||
|
||||
extension Range where Bound: _SQLExpressible {
|
||||
/// Returns an SQL expression that compares the inclusion of a value in
|
||||
extension Range where Bound: SQLExpressible {
|
||||
/// Returns an SQL expression that checks the inclusion of a value in
|
||||
/// a range.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
@@ -344,9 +344,9 @@ extension Range where Bound: _SQLExpressible {
|
||||
}
|
||||
}
|
||||
|
||||
extension ClosedRange where Bound: _SQLExpressible {
|
||||
/// Returns an SQL expression that compares the inclusion of a value in
|
||||
/// a range.
|
||||
extension ClosedRange where Bound: SQLExpressible {
|
||||
/// Returns an SQL expression that checks the inclusion of a value in
|
||||
/// an range.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func contains(_ element: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
@@ -354,8 +354,8 @@ extension ClosedRange where Bound: _SQLExpressible {
|
||||
}
|
||||
}
|
||||
|
||||
extension CountableRange where Bound: _SQLExpressible {
|
||||
/// Returns an SQL expression that compares the inclusion of a value in
|
||||
extension CountableRange where Bound: SQLExpressible {
|
||||
/// Returns an SQL expression that checks the inclusion of a value in
|
||||
/// a range.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
@@ -364,8 +364,8 @@ extension CountableRange where Bound: _SQLExpressible {
|
||||
}
|
||||
}
|
||||
|
||||
extension CountableClosedRange where Bound: _SQLExpressible {
|
||||
/// Returns an SQL expression that compares the inclusion of a value in
|
||||
extension CountableClosedRange where Bound: SQLExpressible {
|
||||
/// Returns an SQL expression that checks the inclusion of a value in
|
||||
/// a range.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
@@ -377,7 +377,7 @@ extension CountableClosedRange where Bound: _SQLExpressible {
|
||||
|
||||
// MARK: - Operator IN
|
||||
|
||||
extension Sequence where Self.Iterator.Element: _SQLExpressible {
|
||||
extension Sequence where Self.Iterator.Element: SQLExpressible {
|
||||
/// Returns an SQL expression that checks the inclusion of a value in
|
||||
/// a sequence.
|
||||
///
|
||||
@@ -393,14 +393,14 @@ extension Sequence where Self.Iterator.Element: _SQLExpressible {
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func === (lhs: _SpecificSQLExpressible, rhs: _SQLExpressible?) -> _SQLExpression {
|
||||
public func === (lhs: _SpecificSQLExpressible, rhs: SQLExpressible?) -> _SQLExpression {
|
||||
return .isOperator(lhs.sqlExpression, rhs?.sqlExpression ?? .value(nil))
|
||||
}
|
||||
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func === (lhs: _SQLExpressible?, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
public func === (lhs: SQLExpressible?, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
return .isOperator(lhs?.sqlExpression ?? .value(nil), rhs.sqlExpression)
|
||||
}
|
||||
|
||||
@@ -417,14 +417,14 @@ public func === (lhs: _SpecificSQLExpressible, rhs: _SpecificSQLExpressible) ->
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func !== (lhs: _SpecificSQLExpressible, rhs: _SQLExpressible?) -> _SQLExpression {
|
||||
public func !== (lhs: _SpecificSQLExpressible, rhs: SQLExpressible?) -> _SQLExpression {
|
||||
return .isNotOperator(lhs.sqlExpression, rhs?.sqlExpression ?? .value(nil))
|
||||
}
|
||||
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func !== (lhs: _SQLExpressible?, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
public func !== (lhs: SQLExpressible?, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
return .isNotOperator(lhs?.sqlExpression ?? .value(nil), rhs.sqlExpression)
|
||||
}
|
||||
|
||||
@@ -441,14 +441,14 @@ public func !== (lhs: _SpecificSQLExpressible, rhs: _SpecificSQLExpressible) ->
|
||||
/// Returns an SQL logical expression.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func || (lhs: _SpecificSQLExpressible, rhs: _SQLExpressible) -> _SQLExpression {
|
||||
public func || (lhs: _SpecificSQLExpressible, rhs: SQLExpressible) -> _SQLExpression {
|
||||
return .infixOperator("OR", lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// Returns an SQL logical expression.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func || (lhs: _SQLExpressible, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
public func || (lhs: SQLExpressible, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
return .infixOperator("OR", lhs.sqlExpression, rhs.sqlExpression)
|
||||
}
|
||||
|
||||
|
||||
@@ -285,39 +285,18 @@ struct _SQLLimit {
|
||||
}
|
||||
|
||||
|
||||
// MARK: - _SQLExpressible
|
||||
|
||||
public protocol _SQLExpressible {
|
||||
|
||||
/// This property is an implementation detail of the query interface.
|
||||
/// Do not use it directly.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#the-query-interface
|
||||
var sqlExpression: _SQLExpression { get }
|
||||
}
|
||||
|
||||
// Conformance to _SQLExpressible
|
||||
extension DatabaseValueConvertible {
|
||||
|
||||
/// This property is an implementation detail of the query interface.
|
||||
/// Do not use it directly.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#the-query-interface
|
||||
public var sqlExpression: _SQLExpression {
|
||||
return .value(self)
|
||||
}
|
||||
}
|
||||
// MARK: - _SpecificSQLExpressible
|
||||
|
||||
/// This protocol is an implementation detail of the query interface.
|
||||
/// Do not use it directly.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#the-query-interface
|
||||
public protocol _SpecificSQLExpressible : _SQLExpressible {
|
||||
// _SQLExpressible can be adopted by Swift standard types, and user
|
||||
// types, through the DatabaseValueConvertible protocol, which inherits
|
||||
// from _SQLExpressible.
|
||||
public protocol _SpecificSQLExpressible : SQLExpressible {
|
||||
// SQLExpressible can be adopted by Swift standard types, and user
|
||||
// types, through the DatabaseValueConvertible protocol which inherits
|
||||
// from SQLExpressible.
|
||||
//
|
||||
// For example, Int adopts _SQLExpressible through
|
||||
// For example, Int adopts SQLExpressible through
|
||||
// DatabaseValueConvertible.
|
||||
//
|
||||
// _SpecificSQLExpressible, on the other side, is not adopted by any
|
||||
@@ -328,8 +307,8 @@ public protocol _SpecificSQLExpressible : _SQLExpressible {
|
||||
// spill out. The three declarations below have no chance overloading a
|
||||
// Swift-defined operator, or a user-defined operator:
|
||||
//
|
||||
// - ==(_SQLExpressible, _SpecificSQLExpressible)
|
||||
// - ==(_SpecificSQLExpressible, _SQLExpressible)
|
||||
// - ==(SQLExpressible, _SpecificSQLExpressible)
|
||||
// - ==(_SpecificSQLExpressible, SQLExpressible)
|
||||
// - ==(_SpecificSQLExpressible, _SpecificSQLExpressible)
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ extension Database {
|
||||
/// - ifNotExists: If false, no error is thrown if index already exists.
|
||||
/// - condition: If not nil, creates a partial index
|
||||
/// (see https://www.sqlite.org/partialindex.html).
|
||||
public func create(index name: String, on table: String, columns: [String], unique: Bool = false, ifNotExists: Bool = false, condition: _SQLExpressible? = nil) throws {
|
||||
public func create(index name: String, on table: String, columns: [String], unique: Bool = false, ifNotExists: Bool = false, condition: SQLExpressible? = nil) throws {
|
||||
let definition = IndexDefinition(name: name, table: table, columns: columns, unique: unique, ifNotExists: ifNotExists, condition: condition?.sqlExpression)
|
||||
let sql = definition.sql()
|
||||
try execute(sql)
|
||||
@@ -254,7 +254,7 @@ public final class TableDefinition {
|
||||
/// See https://www.sqlite.org/lang_createtable.html#ckconst
|
||||
///
|
||||
/// - parameter condition: The checked condition
|
||||
public func check(_ condition: _SQLExpressible) {
|
||||
public func check(_ condition: SQLExpressible) {
|
||||
checkConstraints.append(condition.sqlExpression)
|
||||
}
|
||||
|
||||
@@ -500,7 +500,7 @@ public final class ColumnDefinition {
|
||||
/// - parameter condition: A closure whose argument is an Column that
|
||||
/// represents the defined column, and returns the expression to check.
|
||||
/// - returns: Self so that you can further refine the column definition.
|
||||
@discardableResult public func check(_ condition: @noescape (Column) -> _SQLExpressible) -> Self {
|
||||
@discardableResult public func check(_ condition: @noescape (Column) -> SQLExpressible) -> Self {
|
||||
checkExpression = condition(Column(name)).sqlExpression
|
||||
return self
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user