Standardize void types
Let's follow the Apple convention: - () for parameters - Void for return types https://devforums.apple.com/message/1133616#1133616 Signed-off-by: Stephen Celis <stephen@stephencelis.com>
This commit is contained in:
Родитель
533e47e6d5
Коммит
5794555c91
|
@ -378,7 +378,7 @@ class DatabaseTests: SQLiteTestCase {
|
|||
XCTAssertEqual(1, db.scalar("SELECT ? = ? COLLATE \"NO DIACRITIC\"", "cafe", "café") as! Int64)
|
||||
}
|
||||
|
||||
func executeAndWait(block: () -> ()) {
|
||||
func executeAndWait(block: () -> Void) {
|
||||
dispatch_async(dispatch_get_main_queue(), block)
|
||||
waitForExpectationsWithTimeout(5) { error in
|
||||
if let error = error {
|
||||
|
|
|
@ -150,10 +150,10 @@ class StatementTests: SQLiteTestCase {
|
|||
|
||||
}
|
||||
|
||||
func withBlob(block: Blob -> ()) {
|
||||
func withBlob(block: Blob -> Void) {
|
||||
let length = 1
|
||||
let buflen = Int(length) + 1
|
||||
let buffer = UnsafeMutablePointer<()>.alloc(buflen)
|
||||
let buffer = UnsafeMutablePointer<Void>.alloc(buflen)
|
||||
memcpy(buffer, "4", length)
|
||||
block(Blob(bytes: buffer, length: length))
|
||||
buffer.dealloc(buflen)
|
||||
|
|
|
@ -154,7 +154,7 @@
|
|||
DCC6B3A31A9194A800734B78 /* Cipher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Cipher.swift; sourceTree = "<group>"; };
|
||||
DCC6B3A51A9194FB00734B78 /* CipherTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CipherTests.swift; sourceTree = "<group>"; };
|
||||
DCF37F8119DDAC2D001534AA /* DatabaseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseTests.swift; sourceTree = "<group>"; };
|
||||
DCF37F8419DDAF3F001534AA /* StatementTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatementTests.swift; sourceTree = "<group>"; };
|
||||
DCF37F8419DDAF3F001534AA /* StatementTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = StatementTests.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
|
||||
DCF37F8719DDAF79001534AA /* TestHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestHelper.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
|
|
|
@ -392,7 +392,7 @@ public final class Database {
|
|||
/// :param: callback This block is invoked when a statement is executed with
|
||||
/// the compiled SQL as its argument. E.g., pass `println`
|
||||
/// to act as a logger.
|
||||
public func trace(callback: ((SQL: String) -> ())?) {
|
||||
public func trace(callback: ((SQL: String) -> Void)?) {
|
||||
if let callback = callback {
|
||||
trace = { callback(SQL: String.fromCString($0)!) }
|
||||
} else {
|
||||
|
@ -435,7 +435,7 @@ public final class Database {
|
|||
/// :param: callback A callback invoked with the `Operation` (one
|
||||
/// of `.Insert`, `.Update`, or `.Delete`), database name,
|
||||
/// table name, and rowid.
|
||||
public func updateHook(callback: ((operation: Operation, db: String, table: String, rowid: Int64) -> ())?) {
|
||||
public func updateHook(callback: ((operation: Operation, db: String, table: String, rowid: Int64) -> Void)?) {
|
||||
if let callback = callback {
|
||||
updateHook = { operation, db, table, rowid in
|
||||
callback(
|
||||
|
@ -470,7 +470,7 @@ public final class Database {
|
|||
/// Registers a callback to be invoked whenever a transaction rolls back.
|
||||
///
|
||||
/// :param: callback A callback invoked when a transaction is rolled back.
|
||||
public func rollbackHook(callback: (() -> ())?) {
|
||||
public func rollbackHook(callback: (() -> Void)?) {
|
||||
rollbackHook = callback.map { $0 }
|
||||
_SQLiteRollbackHook(handle, rollbackHook)
|
||||
}
|
||||
|
@ -570,7 +570,7 @@ public final class Database {
|
|||
|
||||
private let queue = dispatch_queue_create("SQLite.Database", DISPATCH_QUEUE_SERIAL)
|
||||
|
||||
internal func perform(block: () -> ()) { dispatch_sync(queue, block) }
|
||||
internal func perform(block: () -> Void) { dispatch_sync(queue, block) }
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -90,14 +90,14 @@ public struct Expression<T> {
|
|||
return expression
|
||||
}
|
||||
|
||||
internal static func join(separator: String, _ expressions: [Expressible]) -> Expression<()> {
|
||||
internal static func join(separator: String, _ expressions: [Expressible]) -> Expression<Void> {
|
||||
var (SQL, bindings) = ([String](), [Binding?]())
|
||||
for expressible in expressions {
|
||||
let expression = expressible.expression
|
||||
SQL.append(expression.SQL)
|
||||
bindings.extend(expression.bindings)
|
||||
}
|
||||
return Expression<()>(literal: Swift.join(separator, SQL), bindings)
|
||||
return Expression<Void>(literal: Swift.join(separator, SQL), bindings)
|
||||
}
|
||||
|
||||
internal init<V>(_ expression: Expression<V>) {
|
||||
|
@ -105,11 +105,11 @@ public struct Expression<T> {
|
|||
(ascending, original) = (expression.ascending, expression.original)
|
||||
}
|
||||
|
||||
internal var ordered: Expression<()> {
|
||||
internal var ordered: Expression<Void> {
|
||||
if let ascending = ascending {
|
||||
return Expression.join(" ", [self, Expression(literal: ascending ? "ASC" : "DESC")])
|
||||
}
|
||||
return Expression<()>(self)
|
||||
return Expression<Void>(self)
|
||||
}
|
||||
|
||||
internal var aliased: Expression {
|
||||
|
@ -142,13 +142,13 @@ public struct Expression<T> {
|
|||
|
||||
public protocol Expressible {
|
||||
|
||||
var expression: Expression<()> { get }
|
||||
var expression: Expression<Void> { get }
|
||||
|
||||
}
|
||||
|
||||
extension Blob: Expressible {
|
||||
|
||||
public var expression: Expression<()> {
|
||||
public var expression: Expression<Void> {
|
||||
return Expression(binding: self)
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,7 @@ extension Blob: Expressible {
|
|||
|
||||
extension Bool: Expressible {
|
||||
|
||||
public var expression: Expression<()> {
|
||||
public var expression: Expression<Void> {
|
||||
return Expression(value: self)
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,7 @@ extension Bool: Expressible {
|
|||
|
||||
extension Double: Expressible {
|
||||
|
||||
public var expression: Expression<()> {
|
||||
public var expression: Expression<Void> {
|
||||
return Expression(binding: self)
|
||||
}
|
||||
|
||||
|
@ -172,7 +172,7 @@ extension Double: Expressible {
|
|||
|
||||
extension Int: Expressible {
|
||||
|
||||
public var expression: Expression<()> {
|
||||
public var expression: Expression<Void> {
|
||||
// FIXME: rdar://TODO segfaults during archive // return Expression(value: self)
|
||||
return Expression(binding: datatypeValue)
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ extension Int: Expressible {
|
|||
|
||||
extension Int64: Expressible {
|
||||
|
||||
public var expression: Expression<()> {
|
||||
public var expression: Expression<Void> {
|
||||
return Expression(binding: self)
|
||||
}
|
||||
|
||||
|
@ -189,7 +189,7 @@ extension Int64: Expressible {
|
|||
|
||||
extension String: Expressible {
|
||||
|
||||
public var expression: Expression<()> {
|
||||
public var expression: Expression<Void> {
|
||||
return Expression(binding: self)
|
||||
}
|
||||
|
||||
|
@ -197,15 +197,15 @@ extension String: Expressible {
|
|||
|
||||
extension Expression: Expressible {
|
||||
|
||||
public var expression: Expression<()> {
|
||||
return Expression<()>(self)
|
||||
public var expression: Expression<Void> {
|
||||
return Expression<Void>(self)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension Query: Expressible {
|
||||
|
||||
public var expression: Expression<()> {
|
||||
public var expression: Expression<Void> {
|
||||
if tableName.original != nil {
|
||||
return selectExpression.alias(tableName)
|
||||
}
|
||||
|
@ -587,17 +587,17 @@ public func abs<V: Value where V.Datatype: Number>(expression: Expression<V?>) -
|
|||
|
||||
// FIXME: support Expression<V?>..., Expression<V> when Swift supports inner variadic signatures
|
||||
public func coalesce<V>(expressions: Expression<V?>...) -> Expression<V?> {
|
||||
return wrap(__FUNCTION__, Expression<()>.join(", ", expressions.map { $0 } as [Expressible]))
|
||||
return wrap(__FUNCTION__, Expression<Void>.join(", ", expressions.map { $0 } as [Expressible]))
|
||||
}
|
||||
|
||||
public func ifnull<V: Expressible>(expression: Expression<V?>, defaultValue: V) -> Expression<V> {
|
||||
return wrap(__FUNCTION__, Expression<()>.join(", ", [expression, defaultValue]))
|
||||
return wrap(__FUNCTION__, Expression<Void>.join(", ", [expression, defaultValue]))
|
||||
}
|
||||
public func ifnull<V: Expressible>(expression: Expression<V?>, defaultValue: Expression<V>) -> Expression<V> {
|
||||
return wrap(__FUNCTION__, Expression<()>.join(", ", [expression, defaultValue]))
|
||||
return wrap(__FUNCTION__, Expression<Void>.join(", ", [expression, defaultValue]))
|
||||
}
|
||||
public func ifnull<V: Expressible>(expression: Expression<V?>, defaultValue: Expression<V?>) -> Expression<V> {
|
||||
return wrap(__FUNCTION__, Expression<()>.join(", ", [expression, defaultValue]))
|
||||
return wrap(__FUNCTION__, Expression<Void>.join(", ", [expression, defaultValue]))
|
||||
}
|
||||
public func ?? <V: Expressible>(expression: Expression<V?>, defaultValue: V) -> Expression<V> {
|
||||
return ifnull(expression, defaultValue)
|
||||
|
@ -619,51 +619,51 @@ public func ltrim(expression: Expression<String>) -> Expression<String> { return
|
|||
public func ltrim(expression: Expression<String?>) -> Expression<String?> { return wrap(__FUNCTION__, expression) }
|
||||
|
||||
public func ltrim(expression: Expression<String>, characters: String) -> Expression<String> {
|
||||
return wrap(__FUNCTION__, Expression<()>.join(", ", [expression, characters]))
|
||||
return wrap(__FUNCTION__, Expression<Void>.join(", ", [expression, characters]))
|
||||
}
|
||||
public func ltrim(expression: Expression<String?>, characters: String) -> Expression<String?> {
|
||||
return wrap(__FUNCTION__, Expression<()>.join(", ", [expression, characters]))
|
||||
return wrap(__FUNCTION__, Expression<Void>.join(", ", [expression, characters]))
|
||||
}
|
||||
|
||||
public func random() -> Expression<Int> { return Expression(literal: __FUNCTION__) }
|
||||
|
||||
public func replace(expression: Expression<String>, match: String, subtitute: String) -> Expression<String> {
|
||||
return wrap(__FUNCTION__, Expression<()>.join(", ", [expression, match, subtitute]))
|
||||
return wrap(__FUNCTION__, Expression<Void>.join(", ", [expression, match, subtitute]))
|
||||
}
|
||||
public func replace(expression: Expression<String?>, match: String, subtitute: String) -> Expression<String?> {
|
||||
return wrap(__FUNCTION__, Expression<()>.join(", ", [expression, match, subtitute]))
|
||||
return wrap(__FUNCTION__, Expression<Void>.join(", ", [expression, match, subtitute]))
|
||||
}
|
||||
|
||||
public func round(expression: Expression<Double>) -> Expression<Double> { return wrap(__FUNCTION__, expression) }
|
||||
public func round(expression: Expression<Double?>) -> Expression<Double?> { return wrap(__FUNCTION__, expression) }
|
||||
public func round(expression: Expression<Double>, precision: Int) -> Expression<Double> {
|
||||
return wrap(__FUNCTION__, Expression<()>.join(", ", [expression, precision]))
|
||||
return wrap(__FUNCTION__, Expression<Void>.join(", ", [expression, precision]))
|
||||
}
|
||||
public func round(expression: Expression<Double?>, precision: Int) -> Expression<Double?> {
|
||||
return wrap(__FUNCTION__, Expression<()>.join(", ", [expression, precision]))
|
||||
return wrap(__FUNCTION__, Expression<Void>.join(", ", [expression, precision]))
|
||||
}
|
||||
|
||||
public func rtrim(expression: Expression<String>) -> Expression<String> { return wrap(__FUNCTION__, expression) }
|
||||
public func rtrim(expression: Expression<String?>) -> Expression<String?> { return wrap(__FUNCTION__, expression) }
|
||||
public func rtrim(expression: Expression<String>, characters: String) -> Expression<String> {
|
||||
return wrap(__FUNCTION__, Expression<()>.join(", ", [expression, characters]))
|
||||
return wrap(__FUNCTION__, Expression<Void>.join(", ", [expression, characters]))
|
||||
}
|
||||
public func rtrim(expression: Expression<String?>, characters: String) -> Expression<String?> {
|
||||
return wrap(__FUNCTION__, Expression<()>.join(", ", [expression, characters]))
|
||||
return wrap(__FUNCTION__, Expression<Void>.join(", ", [expression, characters]))
|
||||
}
|
||||
|
||||
public func substr(expression: Expression<String>, startIndex: Int) -> Expression<String> {
|
||||
return wrap(__FUNCTION__, Expression<()>.join(", ", [expression, startIndex]))
|
||||
return wrap(__FUNCTION__, Expression<Void>.join(", ", [expression, startIndex]))
|
||||
}
|
||||
public func substr(expression: Expression<String?>, startIndex: Int) -> Expression<String?> {
|
||||
return wrap(__FUNCTION__, Expression<()>.join(", ", [expression, startIndex]))
|
||||
return wrap(__FUNCTION__, Expression<Void>.join(", ", [expression, startIndex]))
|
||||
}
|
||||
|
||||
public func substr(expression: Expression<String>, position: Int, length: Int) -> Expression<String> {
|
||||
return wrap(__FUNCTION__, Expression<()>.join(", ", [expression, position, length]))
|
||||
return wrap(__FUNCTION__, Expression<Void>.join(", ", [expression, position, length]))
|
||||
}
|
||||
public func substr(expression: Expression<String?>, position: Int, length: Int) -> Expression<String?> {
|
||||
return wrap(__FUNCTION__, Expression<()>.join(", ", [expression, position, length]))
|
||||
return wrap(__FUNCTION__, Expression<Void>.join(", ", [expression, position, length]))
|
||||
}
|
||||
|
||||
public func substr(expression: Expression<String>, subRange: Range<Int>) -> Expression<String> {
|
||||
|
@ -676,10 +676,10 @@ public func substr(expression: Expression<String?>, subRange: Range<Int>) -> Exp
|
|||
public func trim(expression: Expression<String>) -> Expression<String> { return wrap(__FUNCTION__, expression) }
|
||||
public func trim(expression: Expression<String?>) -> Expression<String?> { return wrap(__FUNCTION__, expression) }
|
||||
public func trim(expression: Expression<String>, characters: String) -> Expression<String> {
|
||||
return wrap(__FUNCTION__, Expression<()>.join(", ", [expression, characters]))
|
||||
return wrap(__FUNCTION__, Expression<Void>.join(", ", [expression, characters]))
|
||||
}
|
||||
public func trim(expression: Expression<String?>, characters: String) -> Expression<String?> {
|
||||
return wrap(__FUNCTION__, Expression<()>.join(", ", [expression, characters]))
|
||||
return wrap(__FUNCTION__, Expression<Void>.join(", ", [expression, characters]))
|
||||
}
|
||||
|
||||
public func upper(expression: Expression<String>) -> Expression<String> { return wrap(__FUNCTION__, expression) }
|
||||
|
@ -727,16 +727,16 @@ public func total<V: Value where V.Datatype: Number>(#distinct: Expression<V>) -
|
|||
public func total<V: Value where V.Datatype: Number>(#distinct: Expression<V?>) -> Expression<Double> { return wrapDistinct("total", distinct) }
|
||||
|
||||
private func wrapDistinct<V, U>(function: String, expression: Expression<V>) -> Expression<U> {
|
||||
return wrap(function, Expression<()>.join(" ", [Expression<()>(literal: "DISTINCT"), expression]))
|
||||
return wrap(function, Expression<Void>.join(" ", [Expression<Void>(literal: "DISTINCT"), expression]))
|
||||
}
|
||||
|
||||
// MARK: - Helper
|
||||
|
||||
public let rowid = Expression<Int64>("ROWID")
|
||||
|
||||
public typealias Star = (Expression<Binding>?, Expression<Binding>?) -> Expression<()>
|
||||
public typealias Star = (Expression<Binding>?, Expression<Binding>?) -> Expression<Void>
|
||||
|
||||
public func * (Expression<Binding>?, Expression<Binding>?) -> Expression<()> {
|
||||
public func * (Expression<Binding>?, Expression<Binding>?) -> Expression<Void> {
|
||||
return Expression(literal: "*")
|
||||
}
|
||||
public func contains<V: Value, C: CollectionType where C.Generator.Element == V, C.Index.Distance == Int>(values: C, column: Expression<V>) -> Expression<Bool> {
|
||||
|
@ -747,7 +747,7 @@ public func contains<V: Value, C: CollectionType where C.Generator.Element == V,
|
|||
return contains(values, Expression<V>(column))
|
||||
}
|
||||
public func contains<V: Value>(values: Query, column: Expression<V>) -> Expression<Bool> {
|
||||
return infix("IN", column, wrap("", values.selectExpression) as Expression<()>)
|
||||
return infix("IN", column, wrap("", values.selectExpression) as Expression<Void>)
|
||||
}
|
||||
|
||||
// MARK: - Modifying
|
||||
|
@ -764,10 +764,10 @@ public typealias Setter = (Expressible, Expressible)
|
|||
/// :returns: A setter that can be used in a Query’s insert and update
|
||||
/// functions.
|
||||
public func set<V: Value>(column: Expression<V>, value: V) -> Setter {
|
||||
return (column, Expression<()>(value: value))
|
||||
return (column, Expression<Void>(value: value))
|
||||
}
|
||||
public func set<V: Value>(column: Expression<V?>, value: V?) -> Setter {
|
||||
return (column, Expression<()>(value: value))
|
||||
return (column, Expression<Void>(value: value))
|
||||
}
|
||||
public func set<V: Value>(column: Expression<V>, value: Expression<V>) -> Setter { return (column, value) }
|
||||
public func set<V: Value>(column: Expression<V>, value: Expression<V?>) -> Setter { return (column, value) }
|
||||
|
|
|
@ -22,23 +22,23 @@
|
|||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
public func fts4(columns: Expression<String>...) -> Expression<()> {
|
||||
public func fts4(columns: Expression<String>...) -> Expression<Void> {
|
||||
return fts4(columns)
|
||||
}
|
||||
|
||||
// TODO: matchinfo, compress, uncompress
|
||||
public func fts4(columns: [Expression<String>], tokenize tokenizer: Tokenizer? = nil) -> Expression<()> {
|
||||
public func fts4(columns: [Expression<String>], tokenize tokenizer: Tokenizer? = nil) -> Expression<Void> {
|
||||
var options = [String: String]()
|
||||
options["tokenize"] = tokenizer?.description
|
||||
return fts("fts4", columns, options)
|
||||
}
|
||||
|
||||
private func fts(function: String, columns: [Expression<String>], options: [String: String]) -> Expression<()> {
|
||||
private func fts(function: String, columns: [Expression<String>], options: [String: String]) -> Expression<Void> {
|
||||
var definitions: [Expressible] = columns.map { $0.expression }
|
||||
for (key, value) in options {
|
||||
definitions.append(Expression<()>(literal: "\(key)=\(value)"))
|
||||
definitions.append(Expression<Void>(literal: "\(key)=\(value)"))
|
||||
}
|
||||
return wrap(function, Expression<()>.join(", ", definitions))
|
||||
return wrap(function, Expression<Void>.join(", ", definitions))
|
||||
}
|
||||
|
||||
public enum Tokenizer {
|
||||
|
|
|
@ -32,7 +32,7 @@ public struct Query {
|
|||
(self.database, self.tableName) = (database, Expression(tableName))
|
||||
}
|
||||
|
||||
private init(_ database: Database, _ tableName: Expression<()>) {
|
||||
private init(_ database: Database, _ tableName: Expression<Void>) {
|
||||
(self.database, self.tableName) = (database, tableName)
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ public struct Query {
|
|||
|
||||
private var columns: [Expressible]?
|
||||
private var distinct: Bool = false
|
||||
internal var tableName: Expression<()>
|
||||
internal var tableName: Expression<Void>
|
||||
private var joins: [(type: JoinType, table: Query, condition: Expression<Bool>)] = []
|
||||
private var filter: Expression<Bool>?
|
||||
private var group: Expressible?
|
||||
|
@ -220,8 +220,8 @@ public struct Query {
|
|||
/// :returns: A query with the given GROUP BY clause applied.
|
||||
public func group(by: [Expressible], having: Expression<Bool>? = nil) -> Query {
|
||||
var query = self
|
||||
var group = Expression<()>.join(" ", [Expression<()>(literal: "GROUP BY"), Expression<()>.join(", ", by)])
|
||||
if let having = having { group = Expression<()>.join(" ", [group, Expression<()>(literal: "HAVING"), having]) }
|
||||
var group = Expression<Void>.join(" ", [Expression<Void>(literal: "GROUP BY"), Expression<Void>.join(", ", by)])
|
||||
if let having = having { group = Expression<Void>.join(" ", [group, Expression<Void>(literal: "HAVING"), having]) }
|
||||
query.group = group
|
||||
return query
|
||||
}
|
||||
|
@ -326,7 +326,7 @@ public struct Query {
|
|||
///
|
||||
/// :returns: A * expression namespaced with the query’s table name or
|
||||
/// alias.
|
||||
public subscript(star: Star) -> Expression<()> {
|
||||
public subscript(star: Star) -> Expression<Void> {
|
||||
return namespace(star(nil, nil))
|
||||
}
|
||||
|
||||
|
@ -337,14 +337,14 @@ public struct Query {
|
|||
return database.prepare(expression.SQL, expression.bindings)
|
||||
}
|
||||
|
||||
internal var selectExpression: Expression<()> {
|
||||
internal var selectExpression: Expression<Void> {
|
||||
var expressions = [selectClause]
|
||||
joinClause.map(expressions.append)
|
||||
whereClause.map(expressions.append)
|
||||
group.map(expressions.append)
|
||||
orderClause.map(expressions.append)
|
||||
limitClause.map(expressions.append)
|
||||
return Expression<()>.join(" ", expressions)
|
||||
return Expression<Void>.join(" ", expressions)
|
||||
}
|
||||
|
||||
/// ON CONFLICT resolutions.
|
||||
|
@ -365,65 +365,65 @@ public struct Query {
|
|||
private func insertStatement(or: OnConflict? = nil, _ values: [Setter]) -> Statement {
|
||||
var insertClause = "INSERT"
|
||||
if let or = or { insertClause = "\(insertClause) OR \(or.rawValue)" }
|
||||
var expressions: [Expressible] = [Expression<()>(literal: "\(insertClause) INTO \(tableName.unaliased.SQL)")]
|
||||
let (c, v) = (Expression<()>.join(", ", values.map { $0.0 }), Expression<()>.join(", ", values.map { $0.1 }))
|
||||
expressions.append(Expression<()>(literal: "(\(c.SQL)) VALUES (\(v.SQL))", c.bindings + v.bindings))
|
||||
var expressions: [Expressible] = [Expression<Void>(literal: "\(insertClause) INTO \(tableName.unaliased.SQL)")]
|
||||
let (c, v) = (Expression<Void>.join(", ", values.map { $0.0 }), Expression<Void>.join(", ", values.map { $0.1 }))
|
||||
expressions.append(Expression<Void>(literal: "(\(c.SQL)) VALUES (\(v.SQL))", c.bindings + v.bindings))
|
||||
whereClause.map(expressions.append)
|
||||
let expression = Expression<()>.join(" ", expressions)
|
||||
let expression = Expression<Void>.join(" ", expressions)
|
||||
return database.prepare(expression.SQL, expression.bindings)
|
||||
}
|
||||
|
||||
private func updateStatement(values: [Setter]) -> Statement {
|
||||
var expressions: [Expressible] = [Expression<()>(literal: "UPDATE \(tableName.unaliased.SQL) SET")]
|
||||
expressions.append(Expression<()>.join(", ", values.map { Expression<()>.join(" = ", [$0, $1]) }))
|
||||
var expressions: [Expressible] = [Expression<Void>(literal: "UPDATE \(tableName.unaliased.SQL) SET")]
|
||||
expressions.append(Expression<Void>.join(", ", values.map { Expression<Void>.join(" = ", [$0, $1]) }))
|
||||
whereClause.map(expressions.append)
|
||||
let expression = Expression<()>.join(" ", expressions)
|
||||
let expression = Expression<Void>.join(" ", expressions)
|
||||
return database.prepare(expression.SQL, expression.bindings)
|
||||
}
|
||||
|
||||
private var deleteStatement: Statement {
|
||||
var expressions: [Expressible] = [Expression<()>(literal: "DELETE FROM \(tableName.unaliased.SQL)")]
|
||||
var expressions: [Expressible] = [Expression<Void>(literal: "DELETE FROM \(tableName.unaliased.SQL)")]
|
||||
whereClause.map(expressions.append)
|
||||
let expression = Expression<()>.join(" ", expressions)
|
||||
let expression = Expression<Void>.join(" ", expressions)
|
||||
return database.prepare(expression.SQL, expression.bindings)
|
||||
}
|
||||
|
||||
// MARK: -
|
||||
|
||||
private var selectClause: Expressible {
|
||||
var expressions: [Expressible] = [Expression<()>(literal: "SELECT")]
|
||||
if distinct { expressions.append(Expression<()>(literal: "DISTINCT")) }
|
||||
expressions.append(Expression<()>.join(", ", (columns ?? [Expression<()>(literal: "*")]).map { $0.expression.aliased }))
|
||||
expressions.append(Expression<()>(literal: "FROM \(tableName.aliased.SQL)"))
|
||||
return Expression<()>.join(" ", expressions)
|
||||
var expressions: [Expressible] = [Expression<Void>(literal: "SELECT")]
|
||||
if distinct { expressions.append(Expression<Void>(literal: "DISTINCT")) }
|
||||
expressions.append(Expression<Void>.join(", ", (columns ?? [Expression<Void>(literal: "*")]).map { $0.expression.aliased }))
|
||||
expressions.append(Expression<Void>(literal: "FROM \(tableName.aliased.SQL)"))
|
||||
return Expression<Void>.join(" ", expressions)
|
||||
}
|
||||
|
||||
private var joinClause: Expressible? {
|
||||
if joins.count == 0 { return nil }
|
||||
return Expression<()>.join(" ", joins.map { type, table, condition in
|
||||
return Expression<Void>.join(" ", joins.map { type, table, condition in
|
||||
let join = (table.columns == nil ? table.tableName : table.expression).aliased
|
||||
return Expression<()>(literal: "\(type.rawValue) JOIN \(join.SQL) ON \(condition.SQL)", join.bindings + condition.bindings)
|
||||
return Expression<Void>(literal: "\(type.rawValue) JOIN \(join.SQL) ON \(condition.SQL)", join.bindings + condition.bindings)
|
||||
})
|
||||
}
|
||||
|
||||
internal var whereClause: Expressible? {
|
||||
if let filter = filter {
|
||||
return Expression<()>(literal: "WHERE \(filter.SQL)", filter.bindings)
|
||||
return Expression<Void>(literal: "WHERE \(filter.SQL)", filter.bindings)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
private var orderClause: Expressible? {
|
||||
if order.count == 0 { return nil }
|
||||
let clause = Expression<()>.join(", ", order.map { $0.expression.ordered })
|
||||
return Expression<()>(literal: "ORDER BY \(clause.SQL)", clause.bindings)
|
||||
let clause = Expression<Void>.join(", ", order.map { $0.expression.ordered })
|
||||
return Expression<Void>(literal: "ORDER BY \(clause.SQL)", clause.bindings)
|
||||
}
|
||||
|
||||
private var limitClause: Expressible? {
|
||||
if let limit = limit {
|
||||
var clause = Expression<()>(literal: "LIMIT \(limit.to)")
|
||||
var clause = Expression<Void>(literal: "LIMIT \(limit.to)")
|
||||
if let offset = limit.offset {
|
||||
clause = Expression<()>.join(" ", [clause, Expression<()>(literal: "OFFSET \(offset)")])
|
||||
clause = Expression<Void>.join(" ", [clause, Expression<Void>(literal: "OFFSET \(offset)")])
|
||||
}
|
||||
return clause
|
||||
}
|
||||
|
@ -732,11 +732,11 @@ public struct QueryGenerator: GeneratorType {
|
|||
|
||||
private lazy var columnNames: [String: Int] = {
|
||||
var (columnNames, idx) = ([String: Int](), 0)
|
||||
column: for each in self.query.columns ?? [Expression<()>(literal: "*")] {
|
||||
column: for each in self.query.columns ?? [Expression<Void>(literal: "*")] {
|
||||
let pair = split(each.expression.SQL) { $0 == "." }
|
||||
let (tableName, column) = (pair.count > 1 ? pair.first : nil, pair.last!)
|
||||
|
||||
func expandGlob(namespace: Bool) -> Query -> () {
|
||||
func expandGlob(namespace: Bool) -> Query -> Void {
|
||||
return { table in
|
||||
var query = Query(table.database, table.tableName.unaliased)
|
||||
if let columns = table.columns { query.columns = columns }
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
public func rtree<T: Value, U: Value where T.Datatype == Int64, U.Datatype == Double>(primaryKey: Expression<T>, columns: Expression<U>...) -> Expression<()> {
|
||||
public func rtree<T: Value, U: Value where T.Datatype == Int64, U.Datatype == Double>(primaryKey: Expression<T>, columns: Expression<U>...) -> Expression<Void> {
|
||||
var definitions: [Expressible] = [primaryKey]
|
||||
definitions.extend(columns.map { $0 })
|
||||
return wrap(__FUNCTION__, Expression<()>.join(", ", definitions))
|
||||
return wrap(__FUNCTION__, Expression<Void>.join(", ", definitions))
|
||||
}
|
||||
|
|
|
@ -28,12 +28,12 @@ public extension Database {
|
|||
#table: Query,
|
||||
temporary: Bool = false,
|
||||
ifNotExists: Bool = false,
|
||||
@noescape _ block: SchemaBuilder -> ()
|
||||
@noescape _ block: SchemaBuilder -> Void
|
||||
) -> Statement {
|
||||
var builder = SchemaBuilder(table)
|
||||
block(builder)
|
||||
let create = createSQL("TABLE", temporary, false, ifNotExists, table.tableName.unaliased.SQL)
|
||||
let columns = Expression<()>.join(", ", builder.columns).compile()
|
||||
let columns = Expression<Void>.join(", ", builder.columns).compile()
|
||||
return run("\(create) (\(columns))")
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ public extension Database {
|
|||
return run("\(create) AS \(expression.SQL)", expression.bindings)
|
||||
}
|
||||
|
||||
public func create(#vtable: Query, ifNotExists: Bool = false, using: Expression<()>) -> Statement {
|
||||
public func create(#vtable: Query, ifNotExists: Bool = false, using: Expression<Void>) -> Statement {
|
||||
let create = createSQL("VIRTUAL TABLE", false, false, ifNotExists, vtable.tableName.unaliased.SQL)
|
||||
return run("\(create) USING \(using.SQL)")
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ public extension Database {
|
|||
references: Expression<V>
|
||||
) -> Statement {
|
||||
return alter(table, define(Expression<V>(column), nil, true, false, check, nil, [
|
||||
Expression<()>(literal: "REFERENCES"), namespace(references)
|
||||
Expression<Void>(literal: "REFERENCES"), namespace(references)
|
||||
]))
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ public extension Database {
|
|||
collate: Collation
|
||||
) -> Statement {
|
||||
return alter(table, define(Expression<V>(column), nil, false, false, check, Expression(value: defaultValue), [
|
||||
Expression<()>(literal: "COLLATE"), Expression<()>(collate.description)
|
||||
Expression<Void>(literal: "COLLATE"), Expression<Void>(collate.description)
|
||||
]))
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ public extension Database {
|
|||
) -> Statement {
|
||||
let value = defaultValue.map { Expression<V>(value: $0) }
|
||||
return alter(table, define(Expression<V>(column), nil, true, false, check, value, [
|
||||
Expression<()>(literal: "COLLATE"), Expression<()>(collate.description)
|
||||
Expression<Void>(literal: "COLLATE"), Expression<Void>(collate.description)
|
||||
]))
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ public extension Database {
|
|||
) -> Statement {
|
||||
let tableName = table.tableName.unaliased.SQL
|
||||
let create = createSQL("INDEX", false, unique, ifNotExists, indexName(tableName, on: columns))
|
||||
let joined = Expression<()>.join(", ", columns.map { $0.expression.ordered })
|
||||
let joined = Expression<Void>.join(", ", columns.map { $0.expression.ordered })
|
||||
return run("\(create) ON \(tableName) (\(joined.compile()))")
|
||||
}
|
||||
|
||||
|
@ -237,7 +237,7 @@ public final class SchemaBuilder {
|
|||
references: Expression<V>
|
||||
) {
|
||||
assertForeignKeysEnabled()
|
||||
let expressions: [Expressible] = [Expression<()>(literal: "REFERENCES"), namespace(references)]
|
||||
let expressions: [Expressible] = [Expression<Void>(literal: "REFERENCES"), namespace(references)]
|
||||
column(name, nil, false, unique, check, nil, expressions)
|
||||
}
|
||||
|
||||
|
@ -262,7 +262,7 @@ public final class SchemaBuilder {
|
|||
references: Expression<V>
|
||||
) {
|
||||
assertForeignKeysEnabled()
|
||||
let expressions: [Expressible] = [Expression<()>(literal: "REFERENCES"), namespace(references)]
|
||||
let expressions: [Expressible] = [Expression<Void>(literal: "REFERENCES"), namespace(references)]
|
||||
column(Expression<Int>(name), nil, true, unique, check, nil, expressions)
|
||||
}
|
||||
|
||||
|
@ -289,7 +289,7 @@ public final class SchemaBuilder {
|
|||
defaultValue value: Expression<V>?,
|
||||
collate: Collation
|
||||
) {
|
||||
let expressions: [Expressible] = [Expression<()>(literal: "COLLATE \(collate)")]
|
||||
let expressions: [Expressible] = [Expression<Void>(literal: "COLLATE \(collate)")]
|
||||
column(name, nil, false, unique, check, value, expressions)
|
||||
}
|
||||
|
||||
|
@ -353,17 +353,17 @@ public final class SchemaBuilder {
|
|||
}
|
||||
|
||||
private func primaryKey(composite: [Expressible]) {
|
||||
let primaryKey = Expression<()>.join(", ", composite)
|
||||
columns.append(Expression<()>(literal: "PRIMARY KEY(\(primaryKey.SQL))", primaryKey.bindings))
|
||||
let primaryKey = Expression<Void>.join(", ", composite)
|
||||
columns.append(Expression<Void>(literal: "PRIMARY KEY(\(primaryKey.SQL))", primaryKey.bindings))
|
||||
}
|
||||
|
||||
public func unique(column: Expressible...) {
|
||||
let unique = Expression<()>.join(", ", column)
|
||||
columns.append(Expression<()>(literal: "UNIQUE(\(unique.SQL))", unique.bindings))
|
||||
let unique = Expression<Void>.join(", ", column)
|
||||
columns.append(Expression<Void>(literal: "UNIQUE(\(unique.SQL))", unique.bindings))
|
||||
}
|
||||
|
||||
public func check(condition: Expression<Bool>) {
|
||||
columns.append(Expression<()>(literal: "CHECK (\(condition.SQL))", condition.bindings))
|
||||
columns.append(Expression<Void>(literal: "CHECK (\(condition.SQL))", condition.bindings))
|
||||
}
|
||||
|
||||
public enum Dependency: String {
|
||||
|
@ -387,11 +387,11 @@ public final class SchemaBuilder {
|
|||
delete: Dependency? = nil
|
||||
) {
|
||||
assertForeignKeysEnabled()
|
||||
var parts: [Expressible] = [Expression<()>(literal: "FOREIGN KEY(\(column.SQL)) REFERENCES", column.bindings)]
|
||||
var parts: [Expressible] = [Expression<Void>(literal: "FOREIGN KEY(\(column.SQL)) REFERENCES", column.bindings)]
|
||||
parts.append(namespace(references))
|
||||
if let update = update { parts.append(Expression<()>(literal: "ON UPDATE \(update.rawValue)")) }
|
||||
if let delete = delete { parts.append(Expression<()>(literal: "ON DELETE \(delete.rawValue)")) }
|
||||
columns.append(Expression<()>.join(" ", parts))
|
||||
if let update = update { parts.append(Expression<Void>(literal: "ON UPDATE \(update.rawValue)")) }
|
||||
if let delete = delete { parts.append(Expression<Void>(literal: "ON DELETE \(delete.rawValue)")) }
|
||||
columns.append(Expression<Void>.join(" ", parts))
|
||||
}
|
||||
|
||||
public func foreignKey<T: Value>(
|
||||
|
@ -410,8 +410,8 @@ public final class SchemaBuilder {
|
|||
update: Dependency? = nil,
|
||||
delete: Dependency? = nil
|
||||
) {
|
||||
let compositeA = Expression<T>(Expression<()>.join(", ", [columns.0, columns.1]))
|
||||
let compositeB = Expression<T>(Expression<()>.join(", ", [references.0, references.1]))
|
||||
let compositeA = Expression<T>(Expression<Void>.join(", ", [columns.0, columns.1]))
|
||||
let compositeB = Expression<T>(Expression<Void>.join(", ", [references.0, references.1]))
|
||||
foreignKey(compositeA, references: compositeB, update: update, delete: delete)
|
||||
}
|
||||
|
||||
|
@ -421,8 +421,8 @@ public final class SchemaBuilder {
|
|||
update: Dependency? = nil,
|
||||
delete: Dependency? = nil
|
||||
) {
|
||||
let compositeA = Expression<T>(Expression<()>.join(", ", [columns.0, columns.1, columns.2]))
|
||||
let compositeB = Expression<T>(Expression<()>.join(", ", [references.0, references.1, references.2]))
|
||||
let compositeA = Expression<T>(Expression<Void>.join(", ", [columns.0, columns.1, columns.2]))
|
||||
let compositeB = Expression<T>(Expression<Void>.join(", ", [references.0, references.1, references.2]))
|
||||
foreignKey(compositeA, references: compositeB, update: update, delete: delete)
|
||||
}
|
||||
|
||||
|
@ -439,7 +439,7 @@ private func namespace(column: Expressible) -> Expressible {
|
|||
let string = String(character)
|
||||
return SQL + (string == "." ? "(" : string)
|
||||
}
|
||||
return Expression<()>(literal: "\(reference))", expression.bindings)
|
||||
return Expression<Void>(literal: "\(reference))", expression.bindings)
|
||||
}
|
||||
|
||||
private func define<V: Value>(
|
||||
|
@ -451,17 +451,17 @@ private func define<V: Value>(
|
|||
defaultValue: Expression<V>?,
|
||||
expressions: [Expressible]?
|
||||
) -> Expressible {
|
||||
var parts: [Expressible] = [Expression<()>(column), Expression<()>(literal: V.declaredDatatype)]
|
||||
var parts: [Expressible] = [Expression<Void>(column), Expression<Void>(literal: V.declaredDatatype)]
|
||||
if let primaryKey = primaryKey {
|
||||
parts.append(Expression<()>(literal: "PRIMARY KEY"))
|
||||
if primaryKey == .Autoincrement { parts.append(Expression<()>(literal: "AUTOINCREMENT")) }
|
||||
parts.append(Expression<Void>(literal: "PRIMARY KEY"))
|
||||
if primaryKey == .Autoincrement { parts.append(Expression<Void>(literal: "AUTOINCREMENT")) }
|
||||
}
|
||||
if !null { parts.append(Expression<()>(literal: "NOT NULL")) }
|
||||
if unique { parts.append(Expression<()>(literal: "UNIQUE")) }
|
||||
if let check = check { parts.append(Expression<()>(literal: "CHECK (\(check.SQL))", check.bindings)) }
|
||||
if let value = defaultValue { parts.append(Expression<()>(literal: "DEFAULT \(value.SQL)", value.bindings)) }
|
||||
if !null { parts.append(Expression<Void>(literal: "NOT NULL")) }
|
||||
if unique { parts.append(Expression<Void>(literal: "UNIQUE")) }
|
||||
if let check = check { parts.append(Expression<Void>(literal: "CHECK (\(check.SQL))", check.bindings)) }
|
||||
if let value = defaultValue { parts.append(Expression<Void>(literal: "DEFAULT \(value.SQL)", value.bindings)) }
|
||||
if let expressions = expressions { parts += expressions }
|
||||
return Expression<()>.join(" ", parts)
|
||||
return Expression<Void>.join(" ", parts)
|
||||
}
|
||||
|
||||
private func createSQL(
|
||||
|
|
|
@ -51,7 +51,7 @@ public struct Blob {
|
|||
|
||||
private let data: NSData
|
||||
|
||||
public var bytes: UnsafePointer<()> {
|
||||
public var bytes: UnsafePointer<Void> {
|
||||
return data.bytes
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ public struct Blob {
|
|||
return data.length
|
||||
}
|
||||
|
||||
public init(bytes: UnsafePointer<()>, length: Int) {
|
||||
public init(bytes: UnsafePointer<Void>, length: Int) {
|
||||
data = NSData(bytes: bytes, length: length)
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче