mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
Promote _SQLExpressible protocol to SQLExpressible
This commit is contained in:
1 parent
ba2aef0468
commit
a132b58227
7 files changed
+119
-98
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:
|
||||
///
|
||||
|
||||
@@ -120,7 +120,7 @@ extension QueryInterfaceRequest {
|
||||
/// Returns a new QueryInterfaceRequest with the provided *predicate* added to the
|
||||
/// eventual set of already applied predicates.
|
||||
@warn_unused_result
|
||||
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)
|
||||
@@ -139,13 +139,13 @@ extension QueryInterfaceRequest {
|
||||
|
||||
/// Returns a new QueryInterfaceRequest grouped according to *expressions*.
|
||||
@warn_unused_result
|
||||
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*.
|
||||
@warn_unused_result
|
||||
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)
|
||||
@@ -160,7 +160,7 @@ extension QueryInterfaceRequest {
|
||||
/// Returns a new QueryInterfaceRequest with the provided *predicate* added to the
|
||||
/// eventual set of already applied predicates.
|
||||
@warn_unused_result
|
||||
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
|
||||
@@ -239,7 +239,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)
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ extension TableMapping {
|
||||
|
||||
/// Returns a QueryInterfaceRequest with the provided *predicate*.
|
||||
@warn_unused_result
|
||||
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 ClosedInterval where Bound: _SQLExpressible {
|
||||
extension ClosedInterval where Bound: SQLExpressible {
|
||||
/// Returns an SQL expression that compares the inclusion of a value in
|
||||
/// an interval.
|
||||
///
|
||||
@@ -189,7 +189,7 @@ extension ClosedInterval where Bound: _SQLExpressible {
|
||||
}
|
||||
}
|
||||
|
||||
extension HalfOpenInterval where Bound: _SQLExpressible {
|
||||
extension HalfOpenInterval where Bound: SQLExpressible {
|
||||
/// Returns an SQL expression that compares the inclusion of a value in
|
||||
/// an interval.
|
||||
///
|
||||
@@ -202,7 +202,7 @@ extension HalfOpenInterval where Bound: _SQLExpressible {
|
||||
|
||||
// MARK: - Operator IN COLLATE
|
||||
|
||||
extension SequenceType where Self.Generator.Element: _SQLExpressible {
|
||||
extension SequenceType where Self.Generator.Element: SQLExpressible {
|
||||
/// Returns an SQL expression that compares the inclusion of a value in
|
||||
/// a sequence.
|
||||
///
|
||||
@@ -218,14 +218,14 @@ extension SequenceType where Self.Generator.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,14 +3,14 @@
|
||||
/// 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 .Equal(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: _SpecificSQLExpressible, rhs: protocol<_SQLExpressible, BooleanType>?) -> _SQLExpression {
|
||||
public func == (lhs: _SpecificSQLExpressible, rhs: protocol<SQLExpressible, BooleanType>?) -> _SQLExpression {
|
||||
if let rhs = rhs {
|
||||
if rhs.boolValue {
|
||||
return lhs.sqlExpression
|
||||
@@ -25,14 +25,14 @@ public func == (lhs: _SpecificSQLExpressible, rhs: protocol<_SQLExpressible, Boo
|
||||
/// 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 .Equal(lhs?.sqlExpression ?? .Value(nil), rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func == (lhs: protocol<_SQLExpressible, BooleanType>?, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
public func == (lhs: protocol<SQLExpressible, BooleanType>?, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
if let lhs = lhs {
|
||||
if lhs.boolValue {
|
||||
return rhs.sqlExpression
|
||||
@@ -57,14 +57,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 .NotEqual(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: _SpecificSQLExpressible, rhs: protocol<_SQLExpressible, BooleanType>?) -> _SQLExpression {
|
||||
public func != (lhs: _SpecificSQLExpressible, rhs: protocol<SQLExpressible, BooleanType>?) -> _SQLExpression {
|
||||
if let rhs = rhs {
|
||||
if rhs.boolValue {
|
||||
return .Not(lhs.sqlExpression)
|
||||
@@ -79,14 +79,14 @@ public func != (lhs: _SpecificSQLExpressible, rhs: protocol<_SQLExpressible, Boo
|
||||
/// 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 .NotEqual(lhs?.sqlExpression ?? .Value(nil), rhs.sqlExpression)
|
||||
}
|
||||
|
||||
/// Returns an SQL expression that compares two values.
|
||||
///
|
||||
/// See https://github.com/groue/GRDB.swift/#sql-operators
|
||||
public func != (lhs: protocol<_SQLExpressible, BooleanType>?, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
public func != (lhs: protocol<SQLExpressible, BooleanType>?, rhs: _SpecificSQLExpressible) -> _SQLExpression {
|
||||
if let lhs = lhs {
|
||||
if lhs.boolValue {
|
||||
return .Not(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,7 +334,7 @@ public func && (lhs: _SpecificSQLExpressible, rhs: _SpecificSQLExpressible) -> _
|
||||
|
||||
// MARK: - Operator BETWEEN
|
||||
|
||||
extension Range where Element: protocol<_SQLExpressible, BidirectionalIndexType> {
|
||||
extension Range where Element: protocol<SQLExpressible, BidirectionalIndexType> {
|
||||
/// Returns an SQL expression that checks the inclusion of a value in
|
||||
/// a range.
|
||||
///
|
||||
@@ -344,7 +344,7 @@ extension Range where Element: protocol<_SQLExpressible, BidirectionalIndexType>
|
||||
}
|
||||
}
|
||||
|
||||
extension ClosedInterval where Bound: _SQLExpressible {
|
||||
extension ClosedInterval where Bound: SQLExpressible {
|
||||
/// Returns an SQL expression that checks the inclusion of a value in
|
||||
/// an interval.
|
||||
///
|
||||
@@ -354,7 +354,7 @@ extension ClosedInterval where Bound: _SQLExpressible {
|
||||
}
|
||||
}
|
||||
|
||||
extension HalfOpenInterval where Bound: _SQLExpressible {
|
||||
extension HalfOpenInterval where Bound: SQLExpressible {
|
||||
/// Returns an SQL expression that checks the inclusion of a value in
|
||||
/// an interval.
|
||||
///
|
||||
@@ -367,7 +367,7 @@ extension HalfOpenInterval where Bound: _SQLExpressible {
|
||||
|
||||
// MARK: - Operator IN
|
||||
|
||||
extension SequenceType where Self.Generator.Element: _SQLExpressible {
|
||||
extension SequenceType where Self.Generator.Element: SQLExpressible {
|
||||
/// Returns an SQL expression that checks the inclusion of a value in
|
||||
/// a sequence.
|
||||
///
|
||||
@@ -383,14 +383,14 @@ extension SequenceType where Self.Generator.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 .Is(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 .Is(lhs?.sqlExpression ?? .Value(nil), rhs.sqlExpression)
|
||||
}
|
||||
|
||||
@@ -407,14 +407,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 .IsNot(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 .IsNot(lhs?.sqlExpression ?? .Value(nil), rhs.sqlExpression)
|
||||
}
|
||||
|
||||
@@ -431,14 +431,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 SQLColumn that
|
||||
/// represents the defined column, and returns the expression to check.
|
||||
/// - returns: Self so that you can further refine the column definition.
|
||||
public func check(@noescape condition: (SQLColumn) -> _SQLExpressible) -> ColumnDefinition {
|
||||
public func check(@noescape condition: (SQLColumn) -> SQLExpressible) -> ColumnDefinition {
|
||||
checkExpression = condition(SQLColumn(name)).sqlExpression
|
||||
return self
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user