diff --git a/.travis.yml b/.travis.yml index ad0f18b9..b33f9af3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,13 @@ language: objective-c -env: - - BUILD_SCHEME="SQLite iOS" - - BUILD_SCHEME="SQLite Mac" +matrix: + include: + - env: BUILD_SCHEME="SQLite iOS" + - env: BUILD_SCHEME="SQLite Mac" + - env: VALIDATOR_SUBSPEC="none" + - env: VALIDATOR_SUBSPEC="standard" + - env: VALIDATOR_SUBSPEC="standalone" before_install: - gem install xcpretty --no-document script: - - make test - - cd CocoaPodsTests && make test + - ./run-tests.sh osx_image: xcode7.3 diff --git a/CocoaPods/appletvos/module.modulemap b/CocoaPods/appletvos/module.modulemap index ec2ba4ad..637d9935 100644 --- a/CocoaPods/appletvos/module.modulemap +++ b/CocoaPods/appletvos/module.modulemap @@ -1,4 +1,4 @@ module CSQLite [system] { - header "/Applications/Xcode-beta.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/sqlite3.h" + header "/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/sqlite3.h" export * } diff --git a/CocoaPods/appletvsimulator/module.modulemap b/CocoaPods/appletvsimulator/module.modulemap index dba9a141..f8b9b671 100644 --- a/CocoaPods/appletvsimulator/module.modulemap +++ b/CocoaPods/appletvsimulator/module.modulemap @@ -1,4 +1,4 @@ module CSQLite [system] { - header "/Applications/Xcode-beta.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include/sqlite3.h" + header "/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include/sqlite3.h" export * } diff --git a/CocoaPods/iphoneos/module.modulemap b/CocoaPods/iphoneos/module.modulemap index e573902c..043db6c4 100644 --- a/CocoaPods/iphoneos/module.modulemap +++ b/CocoaPods/iphoneos/module.modulemap @@ -1,4 +1,4 @@ module CSQLite [system] { - header "/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/sqlite3.h" + header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/sqlite3.h" export * } diff --git a/CocoaPods/iphonesimulator/module.modulemap b/CocoaPods/iphonesimulator/module.modulemap index d718b560..a7b14cbb 100644 --- a/CocoaPods/iphonesimulator/module.modulemap +++ b/CocoaPods/iphonesimulator/module.modulemap @@ -1,4 +1,4 @@ module CSQLite [system] { - header "/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/sqlite3.h" + header "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/sqlite3.h" export * } diff --git a/CocoaPods/macosx/module.modulemap b/CocoaPods/macosx/module.modulemap index ed1225b7..8fc958e6 100644 --- a/CocoaPods/macosx/module.modulemap +++ b/CocoaPods/macosx/module.modulemap @@ -1,4 +1,4 @@ module CSQLite [system] { - header "/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/sqlite3.h" + header "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/sqlite3.h" export * } diff --git a/CocoaPods/watchos/module.modulemap b/CocoaPods/watchos/module.modulemap index 61eb0f7b..62a6c4ee 100644 --- a/CocoaPods/watchos/module.modulemap +++ b/CocoaPods/watchos/module.modulemap @@ -1,4 +1,4 @@ module CSQLite [system] { - header "/Applications/Xcode-beta.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/usr/include/sqlite3.h" + header "/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/usr/include/sqlite3.h" export * } diff --git a/CocoaPods/watchsimulator/module.modulemap b/CocoaPods/watchsimulator/module.modulemap index d384d36b..086fbab2 100644 --- a/CocoaPods/watchsimulator/module.modulemap +++ b/CocoaPods/watchsimulator/module.modulemap @@ -1,4 +1,4 @@ module CSQLite [system] { - header "/Applications/Xcode-beta.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/usr/include/sqlite3.h" + header "/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/usr/include/sqlite3.h" export * } diff --git a/CocoaPodsTests/integration_test.rb b/CocoaPodsTests/integration_test.rb index 325b8493..429a9c77 100755 --- a/CocoaPodsTests/integration_test.rb +++ b/CocoaPodsTests/integration_test.rb @@ -13,6 +13,7 @@ def test_validate_project def validator @validator ||= TestRunningValidator.new(podspec, []).tap do |validator| + subspec = ENV["VALIDATOR_SUBSPEC"] validator.test_files = Dir["#{project_test_dir}/*.swift"] validator.config.verbose = true validator.no_clean = true @@ -20,6 +21,11 @@ def validator validator.fail_fast = true validator.local = true validator.allow_warnings = true + if subspec == "none" + validator.no_subspecs = true + else + validator.only_subspec = subspec + end end end diff --git a/Documentation/Index.md b/Documentation/Index.md index 0579e6f3..b5f325f0 100644 --- a/Documentation/Index.md +++ b/Documentation/Index.md @@ -406,7 +406,7 @@ The `column` function is used for a single column definition. It takes an [expre t.column(email, collate: .Nocase) // "email" TEXT NOT NULL COLLATE "NOCASE" - t.column(name, collate: .Rtrim) + t.column(name, collate: .rtrim) // "name" TEXT COLLATE "RTRIM" ``` @@ -999,7 +999,7 @@ The `addColumn` function shares several of the same [`column` function parameter try db.run(users.addColumn(email, collate: .Nocase)) // ALTER TABLE "users" ADD COLUMN "email" TEXT NOT NULL COLLATE "NOCASE" - try db.run(users.addColumn(name, collate: .Rtrim)) + try db.run(users.addColumn(name, collate: .rtrim)) // ALTER TABLE "users" ADD COLUMN "name" TEXT COLLATE "RTRIM" ``` @@ -1388,14 +1388,14 @@ let emails = VirtualTable("emails") let subject = Expression("subject") let body = Expression("body") -try db.run(emails.create(.FTS4(subject, body))) +try db.run(emails.create(.fts4(subject, body))) // CREATE VIRTUAL TABLE "emails" USING fts4("subject", "body") ``` We can specify a [tokenizer](http://www.sqlite.org/fts3.html#tokenizer) using the `tokenize` parameter. ``` swift -try db.run(emails.create(.FTS4([subject, body], tokenize: .Porter))) +try db.run(emails.create(.fts4([subject, body], tokenize: .Porter))) // CREATE VIRTUAL TABLE "emails" USING fts4("subject", "body", tokenize=porter) ``` @@ -1409,9 +1409,9 @@ let config = FTS4Config() .column(subject) .column(body, [.unindexed]) .languageId("lid") - .order(.Desc) + .order(.desc) -try db.run(emails.create(.FTS4(config)) +try db.run(emails.create(.fts4(config)) // CREATE VIRTUAL TABLE "emails" USING fts4("subject", "body", notindexed="body", languageid="lid", order="desc") ``` @@ -1443,7 +1443,7 @@ let config = FTS5Config() .column(subject) .column(body, [.unindexed]) -try db.run(emails.create(.FTS5(config)) +try db.run(emails.create(.fts5(config)) // CREATE VIRTUAL TABLE "emails" USING fts5("subject", "body" UNINDEXED) ``` diff --git a/Makefile b/Makefile index 5a452b87..7257b9b1 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,10 @@ BUILD_TOOL = xcodebuild BUILD_SCHEME = SQLite Mac -BUILD_ARGUMENTS = -scheme "$(BUILD_SCHEME)" +ifeq ($(BUILD_SCHEME),SQLite iOS) + BUILD_ARGUMENTS = -scheme "$(BUILD_SCHEME)" -sdk iphonesimulator +else + BUILD_ARGUMENTS = -scheme "$(BUILD_SCHEME)" +endif XCPRETTY := $(shell command -v xcpretty) SWIFTCOV := $(shell command -v swiftcov) diff --git a/SQLite.playground/Contents.swift b/SQLite.playground/Contents.swift index 2015531a..82914293 100644 --- a/SQLite.playground/Contents.swift +++ b/SQLite.playground/Contents.swift @@ -15,7 +15,7 @@ try! db.run(users.create { t in t.column(email, unique: true, check: email.like("%@%")) t.column(name) }) - +e9a8f36 let rowid = try! db.run(users.insert(email <- "alice@mac.com")) let alice = users.filter(id == rowid) diff --git a/SQLite.playground/contents.xcplayground b/SQLite.playground/contents.xcplayground index 35968656..076deff4 100644 --- a/SQLite.playground/contents.xcplayground +++ b/SQLite.playground/contents.xcplayground @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/SQLite.xcodeproj/project.pbxproj b/SQLite.xcodeproj/project.pbxproj index a22fda25..57b5c9c4 100644 --- a/SQLite.xcodeproj/project.pbxproj +++ b/SQLite.xcodeproj/project.pbxproj @@ -679,9 +679,11 @@ TargetAttributes = { 03A65E591C6BB0F50062603F = { CreatedOnToolsVersion = 7.2; + LastSwiftMigration = 0800; }; 03A65E621C6BB0F60062603F = { CreatedOnToolsVersion = 7.2; + LastSwiftMigration = 0800; }; A121AC441CA35C79005A31D1 = { CreatedOnToolsVersion = 7.3; @@ -696,9 +698,11 @@ }; EE247B3B1C3F3ED000AE3E12 = { CreatedOnToolsVersion = 7.2; + LastSwiftMigration = 0800; }; EE247B441C3F3ED000AE3E12 = { CreatedOnToolsVersion = 7.2; + LastSwiftMigration = 0800; }; }; }; @@ -969,6 +973,7 @@ SKIP_INSTALL = YES; "SWIFT_INCLUDE_PATHS[sdk=appletvos*]" = "$(SRCROOT)/CocoaPods/appletvos"; "SWIFT_INCLUDE_PATHS[sdk=appletvsimulator*]" = "$(SRCROOT)/CocoaPods/appletvsimulator"; + SWIFT_VERSION = 3.0; TVOS_DEPLOYMENT_TARGET = 9.1; }; name = Debug; @@ -990,6 +995,7 @@ "SWIFT_INCLUDE_PATHS[sdk=appletvos*]" = "$(SRCROOT)/CocoaPods/appletvos"; "SWIFT_INCLUDE_PATHS[sdk=appletvsimulator*]" = "$(SRCROOT)/CocoaPods/appletvsimulator"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; TVOS_DEPLOYMENT_TARGET = 9.1; }; name = Release; @@ -1002,6 +1008,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.stephencelis.SQLiteTests; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; + SWIFT_VERSION = 3.0; TVOS_DEPLOYMENT_TARGET = 9.1; }; name = Debug; @@ -1015,6 +1022,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; TVOS_DEPLOYMENT_TARGET = 9.1; }; name = Release; @@ -1244,6 +1252,7 @@ SKIP_INSTALL = YES; SWIFT_INCLUDE_PATHS = ""; "SWIFT_INCLUDE_PATHS[sdk=macosx*]" = "$(SRCROOT)/CocoaPods/macosx"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -1269,6 +1278,7 @@ SWIFT_INCLUDE_PATHS = ""; "SWIFT_INCLUDE_PATHS[sdk=macosx*]" = "$(SRCROOT)/CocoaPods/macosx"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -1283,6 +1293,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.stephencelis.SQLiteTests; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -1298,6 +1309,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/SQLite.xcodeproj/xcshareddata/xcschemes/SQLite watchOS.xcscheme b/SQLite.xcodeproj/xcshareddata/xcschemes/SQLite watchOS.xcscheme new file mode 100644 index 00000000..d2088e81 --- /dev/null +++ b/SQLite.xcodeproj/xcshareddata/xcschemes/SQLite watchOS.xcscheme @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SQLite/Core/Blob.swift b/SQLite/Core/Blob.swift index 9657be86..c1f95aa0 100644 --- a/SQLite/Core/Blob.swift +++ b/SQLite/Core/Blob.swift @@ -30,9 +30,9 @@ public struct Blob { self.bytes = bytes } - public init(bytes: UnsafePointer, length: Int) { + public init(bytes: UnsafeRawPointer, length: Int) { self.init(bytes: [UInt8](UnsafeBufferPointer( - start: UnsafePointer(bytes), count: length + start: bytes.assumingMemoryBound(to: UInt8.self), count: length ))) } diff --git a/SQLite/Core/Connection.swift b/SQLite/Core/Connection.swift index 00cbcd3e..2877fdeb 100644 --- a/SQLite/Core/Connection.swift +++ b/SQLite/Core/Connection.swift @@ -38,24 +38,24 @@ public final class Connection { /// An in-memory database (equivalent to `.URI(":memory:")`). /// /// See: - case InMemory + case inMemory /// A temporary, file-backed database (equivalent to `.URI("")`). /// /// See: - case Temporary + case temporary /// A database located at the given URI filename (or path). /// /// See: /// /// - Parameter filename: A URI filename - case URI(String) + case uri(String) } public var handle: OpaquePointer { return _handle! } - private var _handle: OpaquePointer? = nil + fileprivate var _handle: OpaquePointer? = nil /// Initializes a new SQLite connection. /// @@ -71,10 +71,11 @@ public final class Connection { /// Default: `false`. /// /// - Returns: A new database connection. - public init(_ location: Location = .InMemory, readonly: Bool = false) throws { + public init(_ location: Location = .inMemory, readonly: Bool = false) throws { let flags = readonly ? SQLITE_OPEN_READONLY : SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE try check(sqlite3_open_v2(location.description, &_handle, flags | SQLITE_OPEN_FULLMUTEX, nil)) - queue.setSpecific(key: Connection.queueKey, value: ()) + + queue.setSpecific(key: Connection.queueKey, value: self.queueContext) } /// Initializes a new connection to a database. @@ -92,7 +93,7 @@ public final class Connection { /// /// - Returns: A new database connection. public convenience init(_ filename: String, readonly: Bool = false) throws { - try self.init(.URI(filename), readonly: readonly) + try self.init(.uri(filename), readonly: readonly) } deinit { @@ -145,7 +146,7 @@ public final class Connection { /// - bindings: A list of parameters to bind to the statement. /// /// - Returns: A prepared statement. - @warn_unused_result public func prepare(_ statement: String, _ bindings: Binding?...) throws -> Statement { + @discardableResult public func prepare(_ statement: String, _ bindings: Binding?...) throws -> Statement { if !bindings.isEmpty { return try prepare(statement, bindings) } return try Statement(self, statement) } @@ -159,7 +160,7 @@ public final class Connection { /// - bindings: A list of parameters to bind to the statement. /// /// - Returns: A prepared statement. - @warn_unused_result public func prepare(_ statement: String, _ bindings: [Binding?]) throws -> Statement { + @discardableResult public func prepare(_ statement: String, _ bindings: [Binding?]) throws -> Statement { return try prepare(statement).bind(bindings) } @@ -172,7 +173,7 @@ public final class Connection { /// - bindings: A dictionary of named parameters to bind to the statement. /// /// - Returns: A prepared statement. - @warn_unused_result public func prepare(_ statement: String, _ bindings: [String: Binding?]) throws -> Statement { + @discardableResult public func prepare(_ statement: String, _ bindings: [String: Binding?]) throws -> Statement { return try prepare(statement).bind(bindings) } @@ -238,7 +239,7 @@ public final class Connection { /// - bindings: A list of parameters to bind to the statement. /// /// - Returns: The first value of the first row returned. - @warn_unused_result public func scalar(_ statement: String, _ bindings: Binding?...) -> Binding? { + @discardableResult public func scalar(_ statement: String, _ bindings: Binding?...) -> Binding? { return scalar(statement, bindings) } @@ -252,7 +253,7 @@ public final class Connection { /// - bindings: A list of parameters to bind to the statement. /// /// - Returns: The first value of the first row returned. - @warn_unused_result public func scalar(_ statement: String, _ bindings: [Binding?]) -> Binding? { + @discardableResult public func scalar(_ statement: String, _ bindings: [Binding?]) -> Binding? { return try! prepare(statement).scalar(bindings) } @@ -266,7 +267,7 @@ public final class Connection { /// - bindings: A dictionary of named parameters to bind to the statement. /// /// - Returns: The first value of the first row returned. - @warn_unused_result public func scalar(_ statement: String, _ bindings: [String: Binding?]) -> Binding? { + @discardableResult public func scalar(_ statement: String, _ bindings: [String: Binding?]) -> Binding? { return try! prepare(statement).scalar(bindings) } @@ -303,7 +304,7 @@ public final class Connection { /// must throw to roll the transaction back. /// /// - Throws: `Result.Error`, and rethrows. - public func transaction(mode: TransactionMode = .Deferred, block: () throws -> Void) throws { + public func transaction(_ mode: TransactionMode = .Deferred, block: @escaping () throws -> Void) throws { try transaction("BEGIN \(mode.rawValue) TRANSACTION", block, "COMMIT TRANSACTION", or: "ROLLBACK TRANSACTION") } @@ -323,14 +324,14 @@ public final class Connection { /// The block must throw to roll the savepoint back. /// /// - Throws: `SQLite.Result.Error`, and rethrows. - public func savepoint(_ name: String = NSUUID().uuidString, block: () throws -> Void) throws { + public func savepoint(_ name: String = UUID().uuidString, block: @escaping () throws -> Void) throws { let name = name.quote("'") let savepoint = "SAVEPOINT \(name)" try transaction(savepoint, block, "RELEASE \(savepoint)", or: "ROLLBACK TO \(savepoint)") } - private func transaction(_ begin: String, _ block: () throws -> Void, _ commit: String, or rollback: String) throws { + fileprivate func transaction(_ begin: String, _ block: @escaping () throws -> Void, _ commit: String, or rollback: String) throws { return try sync { try self.run(begin) do { @@ -364,21 +365,21 @@ public final class Connection { /// busy error would otherwise be returned. It’s passed the number of /// times it’s been called for this lock. If it returns `true`, it will /// try again. If it returns `false`, no further attempts will be made. - public func busyHandler(callback: ((tries: Int) -> Bool)?) { + public func busyHandler(_ callback: ((_ tries: Int) -> Bool)?) { guard let callback = callback else { sqlite3_busy_handler(handle, nil, nil) busyHandler = nil return } - let box: BusyHandler = { callback(tries: Int($0)) ? 1 : 0 } + let box: BusyHandler = { callback(Int($0)) ? 1 : 0 } sqlite3_busy_handler(handle, { callback, tries in unsafeBitCast(callback, to: BusyHandler.self)(tries) - }, unsafeBitCast(box, to: UnsafeMutablePointer.self)) + }, unsafeBitCast(box, to: UnsafeMutableRawPointer.self)) busyHandler = box } - private typealias BusyHandler = @convention(block) (Int32) -> Int32 - private var busyHandler: BusyHandler? + fileprivate typealias BusyHandler = @convention(block) (Int32) -> Int32 + fileprivate var busyHandler: BusyHandler? /// Sets a handler to call when a statement is executed with the compiled /// SQL. @@ -387,7 +388,7 @@ public final class Connection { /// with the compiled SQL as its argument. /// /// db.trace { SQL in print(SQL) } - public func trace(callback: ((String) -> Void)?) { + public func trace(_ callback: ((String) -> Void)?) { guard let callback = callback else { sqlite3_trace(handle, nil, nil) trace = nil @@ -397,11 +398,11 @@ public final class Connection { let box: Trace = { callback(String(validatingUTF8: $0)!) } sqlite3_trace(handle, { callback, SQL in unsafeBitCast(callback, to: Trace.self)(SQL!) - }, unsafeBitCast(box, to: UnsafeMutablePointer.self)) + }, unsafeBitCast(box, to: UnsafeMutableRawPointer.self)) trace = box } - private typealias Trace = @convention(block) (UnsafePointer) -> Void - private var trace: Trace? + fileprivate typealias Trace = @convention(block) (UnsafePointer) -> Void + fileprivate var trace: Trace? /// Registers a callback to be invoked whenever a row is inserted, updated, /// or deleted in a rowid table. @@ -409,7 +410,7 @@ public final class Connection { /// - Parameter 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) -> Void)?) { + public func updateHook(_ callback: ((_ operation: Operation, _ db: String, _ table: String, _ rowid: Int64) -> Void)?) { guard let callback = callback else { sqlite3_update_hook(handle, nil, nil) updateHook = nil @@ -418,26 +419,26 @@ public final class Connection { let box: UpdateHook = { callback( - operation: Operation(rawValue: $0), - db: String(validatingUTF8: $1)!, - table: String(validatingUTF8: $2)!, - rowid: $3 + Operation(rawValue: $0), + String(validatingUTF8: $1)!, + String(validatingUTF8: $2)!, + $3 ) } sqlite3_update_hook(handle, { callback, operation, db, table, rowid in unsafeBitCast(callback, to: UpdateHook.self)(operation, db!, table!, rowid) - }, unsafeBitCast(box, to: UnsafeMutablePointer.self)) + }, unsafeBitCast(box, to: UnsafeMutableRawPointer.self)) updateHook = box } - private typealias UpdateHook = @convention(block) (Int32, UnsafePointer, UnsafePointer, Int64) -> Void - private var updateHook: UpdateHook? + fileprivate typealias UpdateHook = @convention(block) (Int32, UnsafePointer, UnsafePointer, Int64) -> Void + fileprivate var updateHook: UpdateHook? /// Registers a callback to be invoked whenever a transaction is committed. /// /// - Parameter callback: A callback invoked whenever a transaction is /// committed. If this callback throws, the transaction will be rolled /// back. - public func commitHook(callback: (() throws -> Void)?) { + public func commitHook(_ callback: (() throws -> Void)?) { guard let callback = callback else { sqlite3_commit_hook(handle, nil, nil) commitHook = nil @@ -454,17 +455,17 @@ public final class Connection { } sqlite3_commit_hook(handle, { callback in unsafeBitCast(callback, to: CommitHook.self)() - }, unsafeBitCast(box, to: UnsafeMutablePointer.self)) + }, unsafeBitCast(box, to: UnsafeMutableRawPointer.self)) commitHook = box } - private typealias CommitHook = @convention(block) () -> Int32 - private var commitHook: CommitHook? + fileprivate typealias CommitHook = @convention(block) () -> Int32 + fileprivate var commitHook: CommitHook? /// Registers a callback to be invoked whenever a transaction rolls back. /// /// - Parameter callback: A callback invoked when a transaction is rolled /// back. - public func rollbackHook(callback: (() -> Void)?) { + public func rollbackHook(_ callback: (() -> Void)?) { guard let callback = callback else { sqlite3_rollback_hook(handle, nil, nil) rollbackHook = nil @@ -474,11 +475,11 @@ public final class Connection { let box: RollbackHook = { callback() } sqlite3_rollback_hook(handle, { callback in unsafeBitCast(callback, to: RollbackHook.self)() - }, unsafeBitCast(box, to: UnsafeMutablePointer.self)) + }, unsafeBitCast(box, to: UnsafeMutableRawPointer.self)) rollbackHook = box } - private typealias RollbackHook = @convention(block) () -> Void - private var rollbackHook: RollbackHook? + fileprivate typealias RollbackHook = @convention(block) () -> Void + fileprivate var rollbackHook: RollbackHook? /// Creates or redefines a custom SQL function. /// @@ -499,11 +500,14 @@ public final class Connection { /// - block: A block of code to run when the function is called. The block /// is called with an array of raw SQL values mapped to the function’s /// parameters and should return a raw SQL value (or nil). - public func createFunction(function: String, argumentCount: UInt? = nil, deterministic: Bool = false, _ block: (args: [Binding?]) -> Binding?) { + public func createFunction(_ function: String, argumentCount: UInt? = nil, deterministic: Bool = false, _ block: @escaping (_ args: [Binding?]) -> Binding?) { let argc = argumentCount.map { Int($0) } ?? -1 let box: Function = { context, argc, argv in let arguments: [Binding?] = (0...self), { context, argc, value in + + sqlite3_create_function_v2(handle, function, Int32(argc), flags, unsafeBitCast(box, to: UnsafeMutableRawPointer.self), { context, argc, value in unsafeBitCast(sqlite3_user_data(context), to: Function.self)(context, argc, value) - }, nil, nil, nil) + }, nil, nil, nil) if functions[function] == nil { self.functions[function] = [:] } functions[function]?[argc] = box } - private typealias Function = @convention(block) (OpaquePointer, Int32, UnsafeMutablePointer) -> Void + private typealias Function = @convention(block) (OpaquePointer?, Int32, UnsafeMutablePointer?) -> Void private var functions = [String: [Int: Function]]() /// Defines a new collating sequence. @@ -555,24 +560,28 @@ public final class Connection { /// /// - block: A collation function that takes two strings and returns the /// comparison result. - public func createCollation(collation: String, _ block: (lhs: String, rhs: String) -> ComparisonResult) { + public func createCollation(_ collation: String, _ block: @escaping (_ lhs: String, _ rhs: String) -> ComparisonResult) { let box: Collation = { lhs, rhs in - Int32(block(lhs: String(validatingUTF8: UnsafePointer(lhs))!, rhs: String(validatingUTF8: UnsafePointer(rhs))!).rawValue) + + let unsafeLhs = lhs.assumingMemoryBound(to: Int8.self) + let unsafeRhs = rhs.assumingMemoryBound(to: Int8.self) + + return Int32(block(String(cString: unsafeLhs), String(cString: unsafeRhs)).rawValue) } - try! check(sqlite3_create_collation_v2(handle, collation, SQLITE_UTF8, unsafeBitCast(box, to: UnsafeMutablePointer.self), { callback, _, lhs, _, rhs in + try! check(sqlite3_create_collation_v2(handle, collation, SQLITE_UTF8, unsafeBitCast(box, to: UnsafeMutableRawPointer.self), { callback, _, lhs, _, rhs in unsafeBitCast(callback, to: Collation.self)(lhs!, rhs!) }, nil)) collations[collation] = box } - private typealias Collation = @convention(block) (UnsafePointer, UnsafePointer) -> Int32 - private var collations = [String: Collation]() + fileprivate typealias Collation = @convention(block) (UnsafeRawPointer, UnsafeRawPointer) -> Int32 + fileprivate var collations = [String: Collation]() // MARK: - Error Handling @discardableResult - func sync(block: () throws -> T) rethrows -> T { + func sync(_ block: @escaping () throws -> T) rethrows -> T { var success: T? - var failure: ErrorProtocol? + var failure: Error? let box: () -> Void = { do { @@ -582,12 +591,14 @@ public final class Connection { } } - if DispatchQueue.getSpecific(key: Connection.queueKey) == queueContext { + // todo: Needs to be double checked. + if DispatchQueue.getSpecific(key: Connection.queueKey) == self.queueContext { box() } else { - dispatch_sync(queue, box) // FIXME: rdar://problem/21389236 + queue.sync(execute: box) // FIXME: rdar://problem/21389236 } + if let failure = failure { try { () -> Void in throw failure }() } @@ -604,13 +615,9 @@ public final class Connection { throw error } - private var queue = DispatchQueue(label: "SQLite.Database", attributes: .serial) - - private static let queueKey = DispatchSpecificKey<()>() -// private static let queueKey = unsafeBitCast(Connection.self, to: UnsafePointer.self) - - private lazy var queueContext: UnsafeMutablePointer = unsafeBitCast(self, to: UnsafeMutablePointer.self) - + fileprivate var queue = DispatchQueue(label: "SQLite.Database", attributes: .concurrent) + fileprivate lazy var queueContext = NSUUID().uuidString + fileprivate static let queueKey = DispatchSpecificKey() } extension Connection : CustomStringConvertible { @@ -625,11 +632,11 @@ extension Connection.Location : CustomStringConvertible { public var description: String { switch self { - case .InMemory: + case .inMemory: return ":memory:" - case .Temporary: + case .temporary: return "" - case .URI(let URI): + case .uri(let URI): return URI } } @@ -640,22 +647,22 @@ extension Connection.Location : CustomStringConvertible { public enum Operation { /// An INSERT operation. - case Insert + case insert /// An UPDATE operation. - case Update + case update /// A DELETE operation. - case Delete + case delete - private init(rawValue: Int32) { + fileprivate init(rawValue: Int32) { switch rawValue { case SQLITE_INSERT: - self = .Insert + self = .insert case SQLITE_UPDATE: - self = .Update + self = .update case SQLITE_DELETE: - self = .Delete + self = .delete default: fatalError("unhandled operation code: \(rawValue)") } @@ -663,17 +670,17 @@ public enum Operation { } -public enum Result : ErrorProtocol { +public enum Result : Error { - private static let successCodes: Set = [SQLITE_OK, SQLITE_ROW, SQLITE_DONE] + fileprivate static let successCodes: Set = [SQLITE_OK, SQLITE_ROW, SQLITE_DONE] - case Error(message: String, code: Int32, statement: Statement?) + case error(message: String, code: Int32, statement: Statement?) init?(errorCode: Int32, connection: Connection, statement: Statement? = nil) { guard !Result.successCodes.contains(errorCode) else { return nil } let message = String(validatingUTF8: sqlite3_errmsg(connection.handle))! - self = Error(message: message, code: errorCode, statement: statement) + self = .error(message: message, code: errorCode, statement: statement) } } @@ -682,7 +689,7 @@ extension Result : CustomStringConvertible { public var description: String { switch self { - case let .Error(message, _, statement): + case let .error(message, _, statement): guard let statement = statement else { return message } return "\(message) (\(statement))" diff --git a/SQLite/Core/Statement.swift b/SQLite/Core/Statement.swift index 5b5cc582..40b70c55 100644 --- a/SQLite/Core/Statement.swift +++ b/SQLite/Core/Statement.swift @@ -31,9 +31,9 @@ import CSQLite /// A single SQL statement. public final class Statement { - private var handle: OpaquePointer? = nil + fileprivate var handle: OpaquePointer? = nil - private let connection: Connection + fileprivate let connection: Connection init(_ connection: Connection, _ SQL: String) throws { self.connection = connection @@ -95,7 +95,7 @@ public final class Statement { return self } - private func bind(_ value: Binding?, atIndex idx: Int) { + fileprivate func bind(_ value: Binding?, atIndex idx: Int) { if value == nil { sqlite3_bind_null(handle, Int32(idx)) } else if let value = value as? Blob { @@ -152,7 +152,7 @@ public final class Statement { /// - Parameter bindings: A list of parameters to bind to the statement. /// /// - Returns: The first value of the first row returned. - @warn_unused_result public func scalar(_ bindings: Binding?...) -> Binding? { + @discardableResult public func scalar(_ bindings: Binding?...) -> Binding? { guard bindings.isEmpty else { return scalar(bindings) } @@ -165,7 +165,7 @@ public final class Statement { /// - Parameter bindings: A list of parameters to bind to the statement. /// /// - Returns: The first value of the first row returned. - @warn_unused_result public func scalar(_ bindings: [Binding?]) -> Binding? { + @discardableResult public func scalar(_ bindings: [Binding?]) -> Binding? { return bind(bindings).scalar() } @@ -174,7 +174,7 @@ public final class Statement { /// statement. /// /// - Returns: The first value of the first row returned. - @warn_unused_result public func scalar(_ bindings: [String: Binding?]) -> Binding? { + @discardableResult public func scalar(_ bindings: [String: Binding?]) -> Binding? { return bind(bindings).scalar() } @@ -182,7 +182,7 @@ public final class Statement { return try connection.sync { try self.connection.check(sqlite3_step(self.handle)) == SQLITE_ROW } } - private func reset(clearBindings shouldClear: Bool = true) { + fileprivate func reset(clearBindings shouldClear: Bool = true) { sqlite3_reset(handle) if (shouldClear) { sqlite3_clear_bindings(handle) } } @@ -216,12 +216,12 @@ extension Statement : CustomStringConvertible { public struct Cursor { - private let handle: OpaquePointer + fileprivate let handle: OpaquePointer - private let columnCount: Int + fileprivate let columnCount: Int - private init(_ statement: Statement) { - handle = statement.handle + fileprivate init(_ statement: Statement) { + handle = statement.handle! columnCount = statement.columnCount } @@ -234,13 +234,13 @@ public struct Cursor { } public subscript(idx: Int) -> String { - return String.fromCString(UnsafePointer(sqlite3_column_text(handle, Int32(idx)))) ?? "" + return String(cString: UnsafePointer(sqlite3_column_text(handle, Int32(idx)))) } public subscript(idx: Int) -> Blob { let bytes = sqlite3_column_blob(handle, Int32(idx)) let length = Int(sqlite3_column_bytes(handle, Int32(idx))) - return Blob(bytes: bytes, length: length) + return Blob(bytes: bytes!, length: length) } // MARK: - @@ -275,7 +275,7 @@ extension Cursor : Sequence { } } - public func iterate() -> AnyIterator { + public func makeIterator() -> AnyIterator { var idx = 0 return AnyIterator { if idx >= self.columnCount { diff --git a/SQLite/Extensions/FTS4.swift b/SQLite/Extensions/FTS4.swift index dcd93ba9..34ff38de 100644 --- a/SQLite/Extensions/FTS4.swift +++ b/SQLite/Extensions/FTS4.swift @@ -24,15 +24,15 @@ extension Module { - @warn_unused_result public static func FTS4(_ column: Expressible, _ more: Expressible...) -> Module { + @discardableResult public static func FTS4(_ column: Expressible, _ more: Expressible...) -> Module { return FTS4([column] + more) } - @warn_unused_result public static func FTS4(_ columns: [Expressible] = [], tokenize tokenizer: Tokenizer? = nil) -> Module { + @discardableResult public static func FTS4(_ columns: [Expressible] = [], tokenize tokenizer: Tokenizer? = nil) -> Module { return FTS4(FTS4Config().columns(columns).tokenizer(tokenizer)) } - @warn_unused_result public static func FTS4(_ config: FTS4Config) -> Module { + @discardableResult public static func FTS4(_ config: FTS4Config) -> Module { return Module(name: "fts4", arguments: config.arguments()) } } @@ -51,15 +51,15 @@ extension VirtualTable { /// /// - Returns: An expression appended with a `MATCH` query against the given /// pattern. - @warn_unused_result public func match(_ pattern: String) -> Expression { + @discardableResult public func match(_ pattern: String) -> Expression { return "MATCH".infix(tableName(), pattern) } - @warn_unused_result public func match(_ pattern: Expression) -> Expression { + @discardableResult public func match(_ pattern: Expression) -> Expression { return "MATCH".infix(tableName(), pattern) } - @warn_unused_result public func match(_ pattern: Expression) -> Expression { + @discardableResult public func match(_ pattern: Expression) -> Expression { return "MATCH".infix(tableName(), pattern) } @@ -73,15 +73,15 @@ extension VirtualTable { /// - Parameter pattern: A pattern to match. /// /// - Returns: A query with the given `WHERE … MATCH` clause applied. - @warn_unused_result public func match(_ pattern: String) -> QueryType { + @discardableResult public func match(_ pattern: String) -> QueryType { return filter(match(pattern)) } - @warn_unused_result public func match(_ pattern: Expression) -> QueryType { + @discardableResult public func match(_ pattern: Expression) -> QueryType { return filter(match(pattern)) } - @warn_unused_result public func match(_ pattern: Expression) -> QueryType { + @discardableResult public func match(_ pattern: Expression) -> QueryType { return filter(match(pattern)) } @@ -93,7 +93,7 @@ public struct Tokenizer { public static let Porter = Tokenizer("porter") - @warn_unused_result public static func Unicode61(removeDiacritics: Bool? = nil, tokenchars: Set = [], separators: Set = []) -> Tokenizer { + @discardableResult public static func Unicode61(_ removeDiacritics: Bool? = nil, tokenchars: Set = [], separators: Set = []) -> Tokenizer { var arguments = [String]() if let removeDiacritics = removeDiacritics { @@ -113,7 +113,7 @@ public struct Tokenizer { return Tokenizer("unicode61", arguments) } - @warn_unused_result public static func Custom(_ name: String) -> Tokenizer { + @discardableResult public static func Custom(_ name: String) -> Tokenizer { return Tokenizer(Tokenizer.moduleName.quote(), [name.quote()]) } @@ -121,12 +121,12 @@ public struct Tokenizer { public let arguments: [String] - private init(_ name: String, _ arguments: [String] = []) { + fileprivate init(_ name: String, _ arguments: [String] = []) { self.name = name self.arguments = arguments } - private static let moduleName = "SQLite.swift" + fileprivate static let moduleName = "SQLite.swift" } @@ -140,15 +140,15 @@ extension Tokenizer : CustomStringConvertible { extension Connection { - public func registerTokenizer(_ submoduleName: String, next: (String) -> (String, Range)?) throws { + public func registerTokenizer(_ submoduleName: String, next: @escaping (String) -> (String, Range)?) throws { try check(_SQLiteRegisterTokenizer(handle, Tokenizer.moduleName, submoduleName) { input, offset, length in let string = String(validatingUTF8: input)! guard let (token, range) = next(string) else { return nil } let view = string.utf8 - offset.memory += string.substringToIndex(range.startIndex).utf8.count - length.memory = Int32(range.startIndex.samePositionIn(view).distanceTo(range.endIndex.samePositionIn(view))) + offset.pointee += string.substring(to: range.lowerBound).utf8.count + length.pointee = Int32(view.distance(from: range.lowerBound.samePosition(in: view), to: range.upperBound.samePosition(in: view))) return token }) } @@ -157,7 +157,7 @@ extension Connection { /// Configuration options shared between the [FTS4](https://www.sqlite.org/fts3.html) and /// [FTS5](https://www.sqlite.org/fts5.html) extensions. -public class FTSConfig { +open class FTSConfig { public enum ColumnOption { /// [The notindexed= option](https://www.sqlite.org/fts3.html#section_6_5) case unindexed @@ -172,12 +172,12 @@ public class FTSConfig { /// Adds a column definition @discardableResult - public func column(_ column: Expressible, _ options: [ColumnOption] = []) -> Self { + open func column(_ column: Expressible, _ options: [ColumnOption] = []) -> Self { self.columnDefinitions.append((column, options)) return self } - public func columns(_ columns: [Expressible]) -> Self { + open func columns(_ columns: [Expressible]) -> Self { for column in columns { self.column(column) } @@ -185,25 +185,25 @@ public class FTSConfig { } /// [Tokenizers](https://www.sqlite.org/fts3.html#tokenizer) - public func tokenizer(tokenizer: Tokenizer?) -> Self { + open func tokenizer(_ tokenizer: Tokenizer?) -> Self { self.tokenizer = tokenizer return self } /// [The prefix= option](https://www.sqlite.org/fts3.html#section_6_6) - public func prefix(prefix: [Int]) -> Self { + open func prefix(_ prefix: [Int]) -> Self { self.prefixes += prefix return self } /// [The content= option](https://www.sqlite.org/fts3.html#section_6_2) - public func externalContent(schema: SchemaType) -> Self { + open func externalContent(_ schema: SchemaType) -> Self { self.externalContentSchema = schema return self } /// [Contentless FTS4 Tables](https://www.sqlite.org/fts3.html#section_6_2_1) - public func contentless() -> Self { + open func contentless() -> Self { self.isContentless = true return self } @@ -222,7 +222,7 @@ public class FTSConfig { if let tokenizer = tokenizer { options.append("tokenize", value: Expression(literal: tokenizer.description)) } - options.appendCommaSeparated("prefix", values: prefixes.sort().map { String($0) }) + options.appendCommaSeparated("prefix", values: prefixes.sorted().map { String($0) }) if isContentless { options.append("content", value: "") } else if let externalContentSchema = externalContentSchema { @@ -270,10 +270,10 @@ public class FTSConfig { } /// Configuration for the [FTS4](https://www.sqlite.org/fts3.html) extension. -public class FTS4Config : FTSConfig { +open class FTS4Config : FTSConfig { /// [The matchinfo= option](https://www.sqlite.org/fts3.html#section_6_4) public enum MatchInfo : CustomStringConvertible { - case FTS3 + case fts3 public var description: String { return "fts3" } @@ -282,14 +282,14 @@ public class FTS4Config : FTSConfig { /// [FTS4 options](https://www.sqlite.org/fts3.html#fts4_options) public enum Order : CustomStringConvertible { /// Data structures are optimized for returning results in ascending order by docid (default) - case Asc + case asc /// FTS4 stores its data in such a way as to optimize returning results in descending order by docid. - case Desc + case desc public var description: String { switch self { - case Asc: return "asc" - case Desc: return "desc" + case .asc: return "asc" + case .desc: return "desc" } } } @@ -304,31 +304,31 @@ public class FTS4Config : FTSConfig { } /// [The compress= and uncompress= options](https://www.sqlite.org/fts3.html#section_6_1) - public func compress(_ functionName: String) -> Self { + open func compress(_ functionName: String) -> Self { self.compressFunction = functionName return self } /// [The compress= and uncompress= options](https://www.sqlite.org/fts3.html#section_6_1) - public func uncompress(_ functionName: String) -> Self { + open func uncompress(_ functionName: String) -> Self { self.uncompressFunction = functionName return self } /// [The languageid= option](https://www.sqlite.org/fts3.html#section_6_3) - public func languageId(_ columnName: String) -> Self { + open func languageId(_ columnName: String) -> Self { self.languageId = columnName return self } /// [The matchinfo= option](https://www.sqlite.org/fts3.html#section_6_4) - public func matchInfo(_ matchInfo: MatchInfo) -> Self { + open func matchInfo(_ matchInfo: MatchInfo) -> Self { self.matchInfo = matchInfo return self } /// [FTS4 options](https://www.sqlite.org/fts3.html#fts4_options) - public func order(_ order: Order) -> Self { + open func order(_ order: Order) -> Self { self.order = order return self } diff --git a/SQLite/Extensions/FTS5.swift b/SQLite/Extensions/FTS5.swift index 97056819..f523ee66 100644 --- a/SQLite/Extensions/FTS5.swift +++ b/SQLite/Extensions/FTS5.swift @@ -23,7 +23,7 @@ // extension Module { - @warn_unused_result public static func FTS5(config: FTS5Config) -> Module { + @discardableResult public static func FTS5(_ config: FTS5Config) -> Module { return Module(name: "fts5", arguments: config.arguments()) } } @@ -32,20 +32,20 @@ extension Module { /// /// **Note:** this is currently only applicable when using SQLite.swift together with a FTS5-enabled version /// of SQLite. -public class FTS5Config : FTSConfig { +open class FTS5Config : FTSConfig { public enum Detail : CustomStringConvertible { /// store rowid, column number, term offset - case Full + case full /// store rowid, column number - case Column + case column /// store rowid - case None + case none public var description: String { switch self { - case Full: return "full" - case Column: return "column" - case None: return "none" + case .full: return "full" + case .column: return "column" + case .none: return "none" } } } @@ -58,19 +58,19 @@ public class FTS5Config : FTSConfig { } /// [External Content Tables](https://www.sqlite.org/fts5.html#section_4_4_2) - public func contentRowId(column: Expressible) -> Self { + open func contentRowId(_ column: Expressible) -> Self { self.contentRowId = column return self } /// [The Columnsize Option](https://www.sqlite.org/fts5.html#section_4_5) - public func columnSize(size: Int) -> Self { + open func columnSize(_ size: Int) -> Self { self.columnSize = size return self } /// [The Detail Option](https://www.sqlite.org/fts5.html#section_4_6) - public func detail(detail: Detail) -> Self { + open func detail(_ detail: Detail) -> Self { self.detail = detail return self } diff --git a/SQLite/Extensions/R*Tree.swift b/SQLite/Extensions/R*Tree.swift index 677e7c10..d514d2b7 100644 --- a/SQLite/Extensions/R*Tree.swift +++ b/SQLite/Extensions/R*Tree.swift @@ -24,7 +24,7 @@ extension Module { - @warn_unused_result public static func RTree(primaryKey: Expression, _ pairs: (Expression, Expression)...) -> Module { + @discardableResult public static func RTree(_ primaryKey: Expression, _ pairs: (Expression, Expression)...) -> Module where T.Datatype == Int64, U.Datatype == Double { var arguments: [Expressible] = [primaryKey] for pair in pairs { diff --git a/SQLite/Foundation.swift b/SQLite/Foundation.swift index 60bc3f40..639b348a 100644 --- a/SQLite/Foundation.swift +++ b/SQLite/Foundation.swift @@ -62,8 +62,8 @@ extension Date : Value { public var dateFormatter: DateFormatter = { let formatter = DateFormatter() formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS" - formatter.locale = Locale(localeIdentifier: "en_US_POSIX") - formatter.timeZone = TimeZone(forSecondsFromGMT: 0) + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) return formatter }() diff --git a/SQLite/Helpers.swift b/SQLite/Helpers.swift index 2bb218bf..f39baaec 100644 --- a/SQLite/Helpers.swift +++ b/SQLite/Helpers.swift @@ -51,14 +51,14 @@ let SQLITE_TRANSIENT = unsafeBitCast(-1, to: sqlite3_destructor_type.self) extension String { - @warn_unused_result func quote(_ mark: Character = "\"") -> String { - let escaped = characters.reduce("") { string, character in + @discardableResult func quote(_ mark: Character = "\"") -> String { + let escaped = characters.reduce("") { string, character in string + (character == mark ? "\(mark)\(mark)" : "\(character)") } return "\(mark)\(escaped)\(mark)" } - @warn_unused_result func join(_ expressions: [Expressible]) -> Expressible { + @discardableResult func join(_ expressions: [Expressible]) -> Expressible { var (template, bindings) = ([String](), [Binding?]()) for expressible in expressions { let expression = expressible.expression @@ -68,7 +68,7 @@ extension String { return Expression(template.joined(separator: self), bindings) } - @warn_unused_result func infix(_ lhs: Expressible, _ rhs: Expressible, wrap: Bool = true) -> Expression { + @discardableResult func infix(_ lhs: Expressible, _ rhs: Expressible, wrap: Bool = true) -> Expression { let expression = Expression(" \(self) ".join([lhs, rhs]).expression) guard wrap else { return expression @@ -76,37 +76,37 @@ extension String { return "".wrap(expression) } - @warn_unused_result func prefix(_ expressions: Expressible) -> Expressible { + @discardableResult func prefix(_ expressions: Expressible) -> Expressible { return "\(self) ".wrap(expressions) as Expression } - @warn_unused_result func prefix(_ expressions: [Expressible]) -> Expressible { + @discardableResult func prefix(_ expressions: [Expressible]) -> Expressible { return "\(self) ".wrap(expressions) as Expression } - @warn_unused_result func wrap(_ expression: Expressible) -> Expression { + @discardableResult func wrap(_ expression: Expressible) -> Expression { return Expression("\(self)(\(expression.expression.template))", expression.expression.bindings) } - @warn_unused_result func wrap(_ expressions: [Expressible]) -> Expression { + @discardableResult func wrap(_ expressions: [Expressible]) -> Expression { return wrap(", ".join(expressions)) } } -@warn_unused_result func infix(_ lhs: Expressible, _ rhs: Expressible, wrap: Bool = true, function: String = #function) -> Expression { +@discardableResult func infix(_ lhs: Expressible, _ rhs: Expressible, wrap: Bool = true, function: String = #function) -> Expression { return function.infix(lhs, rhs, wrap: wrap) } -@warn_unused_result func wrap(_ expression: Expressible, function: String = #function) -> Expression { +@discardableResult func wrap(_ expression: Expressible, function: String = #function) -> Expression { return function.wrap(expression) } -@warn_unused_result func wrap(_ expressions: [Expressible], function: String = #function) -> Expression { +@discardableResult func wrap(_ expressions: [Expressible], function: String = #function) -> Expression { return function.wrap(", ".join(expressions)) } -@warn_unused_result func transcode(_ literal: Binding?) -> String { +@discardableResult func transcode(_ literal: Binding?) -> String { guard let literal = literal else { return "NULL" } switch literal { @@ -119,10 +119,10 @@ extension String { } } -@warn_unused_result func value(_ v: Binding) -> A { +@discardableResult func value(_ v: Binding) -> A { return A.fromDatatypeValue(v as! A.Datatype) as! A } -@warn_unused_result func value(_ v: Binding?) -> A { +@discardableResult func value(_ v: Binding?) -> A { return value(v!) } diff --git a/SQLite/Typed/AggregateFunctions.swift b/SQLite/Typed/AggregateFunctions.swift index 5775e0fe..3bb6b438 100644 --- a/SQLite/Typed/AggregateFunctions.swift +++ b/SQLite/Typed/AggregateFunctions.swift @@ -232,7 +232,7 @@ extension ExpressionType where UnderlyingType : _OptionalType, UnderlyingType.Wr extension ExpressionType where UnderlyingType == Int { - @warn_unused_result static func count(star: Star) -> Expression { + @discardableResult static func count(_ star: Star) -> Expression { return wrap(star(nil, nil)) } @@ -246,6 +246,6 @@ extension ExpressionType where UnderlyingType == Int { /// /// - Returns: An expression returning `count(*)` (when called with the `*` /// function literal). -@warn_unused_result public func count(star: Star) -> Expression { +@discardableResult public func count(_ star: Star) -> Expression { return Expression.count(star) } diff --git a/SQLite/Typed/Collation.swift b/SQLite/Typed/Collation.swift index 5a632055..e2ff9d10 100644 --- a/SQLite/Typed/Collation.swift +++ b/SQLite/Typed/Collation.swift @@ -28,18 +28,18 @@ public enum Collation { /// Compares string by raw data. - case Binary + case binary /// Like binary, but folds uppercase ASCII letters into their lowercase /// equivalents. - case Nocase + case nocase /// Like binary, but strips trailing space. - case Rtrim + case rtrim /// A custom collating sequence identified by the given string, registered /// using `Database.create(collation:…)` - case Custom(String) + case custom(String) } @@ -55,13 +55,13 @@ extension Collation : CustomStringConvertible { public var description : String { switch self { - case Binary: + case .binary: return "BINARY" - case Nocase: + case .nocase: return "NOCASE" - case Rtrim: + case .rtrim: return "RTRIM" - case Custom(let collation): + case .custom(let collation): return collation.quote() } } diff --git a/SQLite/Typed/CoreFunctions.swift b/SQLite/Typed/CoreFunctions.swift index 91822e7e..f25fff41 100644 --- a/SQLite/Typed/CoreFunctions.swift +++ b/SQLite/Typed/CoreFunctions.swift @@ -63,7 +63,7 @@ extension ExpressionType where UnderlyingType == Double { /// // round("salary", 2) /// /// - Returns: A copy of the expression wrapped with the `round` function. - @warn_unused_result public func round(precision: Int? = nil) -> Expression { + @discardableResult public func round(_ precision: Int? = nil) -> Expression { guard let precision = precision else { return wrap([self]) } @@ -83,7 +83,7 @@ extension ExpressionType where UnderlyingType == Double? { /// // round("salary", 2) /// /// - Returns: A copy of the expression wrapped with the `round` function. - @warn_unused_result public func round(precision: Int? = nil) -> Expression { + @discardableResult public func round(_ precision: Int? = nil) -> Expression { guard let precision = precision else { return wrap(self) } @@ -100,13 +100,13 @@ extension ExpressionType where UnderlyingType : Value, UnderlyingType.Datatype = /// // random() /// /// - Returns: An expression calling the `random` function. - @warn_unused_result public static func random() -> Expression { + @discardableResult public static func random() -> Expression { return "random".wrap([]) } } -extension ExpressionType where UnderlyingType == NSData { +extension ExpressionType where UnderlyingType == Data { /// Builds an expression representing the `randomblob` function. /// @@ -116,7 +116,7 @@ extension ExpressionType where UnderlyingType == NSData { /// - Parameter length: Length in bytes. /// /// - Returns: An expression calling the `randomblob` function. - @warn_unused_result public static func random(length: Int) -> Expression { + @discardableResult public static func random(_ length: Int) -> Expression { return "randomblob".wrap([]) } @@ -128,7 +128,7 @@ extension ExpressionType where UnderlyingType == NSData { /// - Parameter length: Length in bytes. /// /// - Returns: An expression calling the `zeroblob` function. - @warn_unused_result public static func allZeros(length: Int) -> Expression { + @discardableResult public static func allZeros(_ length: Int) -> Expression { return "zeroblob".wrap([]) } @@ -145,7 +145,7 @@ extension ExpressionType where UnderlyingType == NSData { } -extension ExpressionType where UnderlyingType == NSData? { +extension ExpressionType where UnderlyingType == Data? { /// Builds a copy of the expression wrapped with the `length` function. /// @@ -213,7 +213,7 @@ extension ExpressionType where UnderlyingType == String { /// /// - Returns: A copy of the expression appended with a `LIKE` query against /// the given pattern. - @warn_unused_result public func like(pattern: String, escape character: Character? = nil) -> Expression { + @discardableResult public func like(_ pattern: String, escape character: Character? = nil) -> Expression { guard let character = character else { return "LIKE".infix(self, pattern) } @@ -231,7 +231,7 @@ extension ExpressionType where UnderlyingType == String { /// /// - Returns: A copy of the expression appended with a `GLOB` query against /// the given pattern. - @warn_unused_result public func glob(pattern: String) -> Expression { + @discardableResult public func glob(_ pattern: String) -> Expression { return "GLOB".infix(self, pattern) } @@ -246,7 +246,7 @@ extension ExpressionType where UnderlyingType == String { /// /// - Returns: A copy of the expression appended with a `MATCH` query /// against the given pattern. - @warn_unused_result public func match(pattern: String) -> Expression { + @discardableResult public func match(_ pattern: String) -> Expression { return "MATCH".infix(self, pattern) } @@ -257,7 +257,7 @@ extension ExpressionType where UnderlyingType == String { /// /// - Returns: A copy of the expression appended with a `REGEXP` query /// against the given pattern. - @warn_unused_result public func regexp(pattern: String) -> Expression { + @discardableResult public func regexp(_ pattern: String) -> Expression { return "REGEXP".infix(self, pattern) } @@ -272,7 +272,7 @@ extension ExpressionType where UnderlyingType == String { /// /// - Returns: A copy of the expression appended with a `COLLATE` clause /// with the given sequence. - @warn_unused_result public func collate(collation: Collation) -> Expression { + @discardableResult public func collate(_ collation: Collation) -> Expression { return "COLLATE".infix(self, collation) } @@ -287,7 +287,7 @@ extension ExpressionType where UnderlyingType == String { /// - Parameter characters: A set of characters to trim. /// /// - Returns: A copy of the expression wrapped with the `ltrim` function. - @warn_unused_result public func ltrim(characters: Set? = nil) -> Expression { + @discardableResult public func ltrim(_ characters: Set? = nil) -> Expression { guard let characters = characters else { return wrap(self) } @@ -305,7 +305,7 @@ extension ExpressionType where UnderlyingType == String { /// - Parameter characters: A set of characters to trim. /// /// - Returns: A copy of the expression wrapped with the `rtrim` function. - @warn_unused_result public func rtrim(characters: Set? = nil) -> Expression { + @discardableResult public func rtrim(_ characters: Set? = nil) -> Expression { guard let characters = characters else { return wrap(self) } @@ -323,7 +323,7 @@ extension ExpressionType where UnderlyingType == String { /// - Parameter characters: A set of characters to trim. /// /// - Returns: A copy of the expression wrapped with the `trim` function. - @warn_unused_result public func trim(characters: Set? = nil) -> Expression { + @discardableResult public func trim(_ characters: Set? = nil) -> Expression { guard let characters = characters else { return wrap([self]) } @@ -343,11 +343,11 @@ extension ExpressionType where UnderlyingType == String { /// - replacement: The replacement string. /// /// - Returns: A copy of the expression wrapped with the `replace` function. - @warn_unused_result public func replace(pattern: String, with replacement: String) -> Expression { + @discardableResult public func replace(_ pattern: String, with replacement: String) -> Expression { return "replace".wrap([self, pattern, replacement]) } - @warn_unused_result public func substring(location: Int, length: Int? = nil) -> Expression { + @discardableResult public func substring(_ location: Int, length: Int? = nil) -> Expression { guard let length = length else { return "substr".wrap([self, location]) } @@ -355,7 +355,7 @@ extension ExpressionType where UnderlyingType == String { } public subscript(range: Range) -> Expression { - return substring(location: range.lowerBound, length: range.upperBound - range.lowerBound) + return substring(range.lowerBound, length: range.upperBound - range.lowerBound) } } @@ -413,7 +413,7 @@ extension ExpressionType where UnderlyingType == String? { /// /// - Returns: A copy of the expression appended with a `LIKE` query against /// the given pattern. - @warn_unused_result public func like(pattern: String, escape character: Character? = nil) -> Expression { + @discardableResult public func like(_ pattern: String, escape character: Character? = nil) -> Expression { guard let character = character else { return "LIKE".infix(self, pattern) } @@ -431,7 +431,7 @@ extension ExpressionType where UnderlyingType == String? { /// /// - Returns: A copy of the expression appended with a `GLOB` query against /// the given pattern. - @warn_unused_result public func glob(pattern: String) -> Expression { + @discardableResult public func glob(_ pattern: String) -> Expression { return "GLOB".infix(self, pattern) } @@ -446,7 +446,7 @@ extension ExpressionType where UnderlyingType == String? { /// /// - Returns: A copy of the expression appended with a `MATCH` query /// against the given pattern. - @warn_unused_result public func match(pattern: String) -> Expression { + @discardableResult public func match(_ pattern: String) -> Expression { return "MATCH".infix(self, pattern) } @@ -457,7 +457,7 @@ extension ExpressionType where UnderlyingType == String? { /// /// - Returns: A copy of the expression appended with a `REGEXP` query /// against the given pattern. - @warn_unused_result public func regexp(pattern: String) -> Expression { + @discardableResult public func regexp(_ pattern: String) -> Expression { return "REGEXP".infix(self, pattern) } @@ -472,7 +472,7 @@ extension ExpressionType where UnderlyingType == String? { /// /// - Returns: A copy of the expression appended with a `COLLATE` clause /// with the given sequence. - @warn_unused_result public func collate(collation: Collation) -> Expression { + @discardableResult public func collate(_ collation: Collation) -> Expression { return "COLLATE".infix(self, collation) } @@ -487,7 +487,7 @@ extension ExpressionType where UnderlyingType == String? { /// - Parameter characters: A set of characters to trim. /// /// - Returns: A copy of the expression wrapped with the `ltrim` function. - @warn_unused_result public func ltrim(characters: Set? = nil) -> Expression { + @discardableResult public func ltrim(_ characters: Set? = nil) -> Expression { guard let characters = characters else { return wrap(self) } @@ -505,7 +505,7 @@ extension ExpressionType where UnderlyingType == String? { /// - Parameter characters: A set of characters to trim. /// /// - Returns: A copy of the expression wrapped with the `rtrim` function. - @warn_unused_result public func rtrim(characters: Set? = nil) -> Expression { + @discardableResult public func rtrim(_ characters: Set? = nil) -> Expression { guard let characters = characters else { return wrap(self) } @@ -523,7 +523,7 @@ extension ExpressionType where UnderlyingType == String? { /// - Parameter characters: A set of characters to trim. /// /// - Returns: A copy of the expression wrapped with the `trim` function. - @warn_unused_result public func trim(characters: Set? = nil) -> Expression { + @discardableResult public func trim(_ characters: Set? = nil) -> Expression { guard let characters = characters else { return wrap(self) } @@ -543,7 +543,7 @@ extension ExpressionType where UnderlyingType == String? { /// - replacement: The replacement string. /// /// - Returns: A copy of the expression wrapped with the `replace` function. - @warn_unused_result public func replace(pattern: String, with replacement: String) -> Expression { + @discardableResult public func replace(_ pattern: String, with replacement: String) -> Expression { return "replace".wrap([self, pattern, replacement]) } @@ -562,7 +562,7 @@ extension ExpressionType where UnderlyingType == String? { /// - length: An optional substring length. /// /// - Returns: A copy of the expression wrapped with the `substr` function. - @warn_unused_result public func substring(location: Int, length: Int? = nil) -> Expression { + @discardableResult public func substring(_ location: Int, length: Int? = nil) -> Expression { guard let length = length else { return "substr".wrap([self, location]) } @@ -579,14 +579,14 @@ extension ExpressionType where UnderlyingType == String? { /// /// - Returns: A copy of the expression wrapped with the `substr` function. public subscript(range: Range) -> Expression { - return substring(location: range.lowerBound, length: range.upperBound - range.lowerBound) + return substring(range.lowerBound, length: range.upperBound - range.lowerBound) } } //extension CollectionType where Generator.Element : _OptionalType, Generator.Element.WrappedType : Value, Index.Distance == Int { // -// @warn_unused_result public func contains(expression: Expression) -> Expression { +// @discardableResult public func contains(expression: Expression) -> Expression { // let templates = [String](count: count, repeatedValue: "?").joinWithSeparator(", ") // return "IN".infix(expression, Expression("(\(templates))", map { $0.datatypeValue })) // } @@ -606,7 +606,7 @@ extension Collection where Iterator.Element : Value, IndexDistance == Int { /// /// - Returns: A copy of the expression prepended with an `IN` check against /// the collection. - @warn_unused_result public func contains(expression: Expression) -> Expression { + @discardableResult public func contains(_ expression: Expression) -> Expression { let templates = [String](repeating: "?", count: count).joined(separator: ", ") return "IN".infix(expression, Expression("(\(templates))", map { $0.datatypeValue })) } @@ -622,7 +622,7 @@ extension Collection where Iterator.Element : Value, IndexDistance == Int { /// /// - Returns: A copy of the expression prepended with an `IN` check against /// the collection. - @warn_unused_result public func contains(expression: Expression) -> Expression { + @discardableResult public func contains(_ expression: Expression) -> Expression { let templates = [String](repeating: "?", count: count).joined(separator: ", ") return "IN".infix(expression, Expression("(\(templates))", map { $0.datatypeValue })) } diff --git a/SQLite/Typed/CustomFunctions.swift b/SQLite/Typed/CustomFunctions.swift index 6ae69495..da7861c6 100644 --- a/SQLite/Typed/CustomFunctions.swift +++ b/SQLite/Typed/CustomFunctions.swift @@ -39,84 +39,84 @@ public extension Connection { /// The assigned types must be explicit. /// /// - Returns: A closure returning an SQL expression to call the function. - public func createFunction(_ function: String, deterministic: Bool = false, _ block: () -> Z) throws -> (() -> Expression) { + public func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping () -> Z) throws -> (() -> Expression) { let fn = try createFunction(function, 0, deterministic) { _ in block() } return { fn([]) } } - public func createFunction(_ function: String, deterministic: Bool = false, _ block: () -> Z?) throws -> (() -> Expression) { + public func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping () -> Z?) throws -> (() -> Expression) { let fn = try createFunction(function, 0, deterministic) { _ in block() } return { fn([]) } } // MARK: - - public func createFunction(_ function: String, deterministic: Bool = false, _ block: (A) -> Z) throws -> ((Expression) -> Expression) { + public func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping (A) -> Z) throws -> ((Expression) -> Expression) { let fn = try createFunction(function, 1, deterministic) { args in block(value(args[0])) } return { arg in fn([arg]) } } - public func createFunction(_ function: String, deterministic: Bool = false, _ block: (A?) -> Z) throws -> ((Expression) -> Expression) { + public func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping (A?) -> Z) throws -> ((Expression) -> Expression) { let fn = try createFunction(function, 1, deterministic) { args in block(args[0].map(value)) } return { arg in fn([arg]) } } - public func createFunction(_ function: String, deterministic: Bool = false, _ block: (A) -> Z?) throws -> ((Expression) -> Expression) { + public func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping (A) -> Z?) throws -> ((Expression) -> Expression) { let fn = try createFunction(function, 1, deterministic) { args in block(value(args[0])) } return { arg in fn([arg]) } } - public func createFunction(_ function: String, deterministic: Bool = false, _ block: (A?) -> Z?) throws -> ((Expression) -> Expression) { + public func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping (A?) -> Z?) throws -> ((Expression) -> Expression) { let fn = try createFunction(function, 1, deterministic) { args in block(args[0].map(value)) } return { arg in fn([arg]) } } // MARK: - - public func createFunction(_ function: String, deterministic: Bool = false, _ block: (A, B) -> Z) throws -> (Expression, Expression) -> Expression { + public func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping (A, B) -> Z) throws -> (Expression, Expression) -> Expression { let fn = try createFunction(function, 1, deterministic) { args in block(value(args[0]), value(args[1])) } return { a, b in fn([a, b]) } } - public func createFunction(_ function: String, deterministic: Bool = false, _ block: (A?, B) -> Z) throws -> (Expression, Expression) -> Expression { + public func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping (A?, B) -> Z) throws -> (Expression, Expression) -> Expression { let fn = try createFunction(function, 1, deterministic) { args in block(args[0].map(value), value(args[1])) } return { a, b in fn([a, b]) } } - public func createFunction(_ function: String, deterministic: Bool = false, _ block: (A, B?) -> Z) throws -> (Expression, Expression) -> Expression { + public func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping (A, B?) -> Z) throws -> (Expression, Expression) -> Expression { let fn = try createFunction(function, 1, deterministic) { args in block(value(args[0]), args[1].map(value)) } return { a, b in fn([a, b]) } } - public func createFunction(_ function: String, deterministic: Bool = false, _ block: (A, B) -> Z?) throws -> (Expression, Expression) -> Expression { + public func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping (A, B) -> Z?) throws -> (Expression, Expression) -> Expression { let fn = try createFunction(function, 1, deterministic) { args in block(value(args[0]), value(args[1])) } return { a, b in fn([a, b]) } } - public func createFunction(_ function: String, deterministic: Bool = false, _ block: (A?, B?) -> Z) throws -> (Expression, Expression) -> Expression { + public func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping (A?, B?) -> Z) throws -> (Expression, Expression) -> Expression { let fn = try createFunction(function, 1, deterministic) { args in block(args[0].map(value), args[1].map(value)) } return { a, b in fn([a, b]) } } - public func createFunction(_ function: String, deterministic: Bool = false, _ block: (A?, B) -> Z?) throws -> (Expression, Expression) -> Expression { + public func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping (A?, B) -> Z?) throws -> (Expression, Expression) -> Expression { let fn = try createFunction(function, 1, deterministic) { args in block(args[0].map(value), value(args[1])) } return { a, b in fn([a, b]) } } - public func createFunction(_ function: String, deterministic: Bool = false, _ block: (A, B?) -> Z?) throws -> (Expression, Expression) -> Expression { + public func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping (A, B?) -> Z?) throws -> (Expression, Expression) -> Expression { let fn = try createFunction(function, 1, deterministic) { args in block(value(args[0]), args[1].map(value)) } return { a, b in fn([a, b]) } } - public func createFunction(_ function: String, deterministic: Bool = false, _ block: (A?, B?) -> Z?) throws -> (Expression, Expression) -> Expression { + public func createFunction(_ function: String, deterministic: Bool = false, _ block: @escaping (A?, B?) -> Z?) throws -> (Expression, Expression) -> Expression { let fn = try createFunction(function, 1, deterministic) { args in block(args[0].map(value), args[1].map(value)) } return { a, b in fn([a, b]) } } // MARK: - - private func createFunction(_ function: String, _ argumentCount: UInt, _ deterministic: Bool, _ block: ([Binding?]) -> Z) throws -> (([Expressible]) -> Expression) { - createFunction(function: function, argumentCount: argumentCount, deterministic: deterministic) { arguments in + fileprivate func createFunction(_ function: String, _ argumentCount: UInt, _ deterministic: Bool, _ block: @escaping ([Binding?]) -> Z) throws -> (([Expressible]) -> Expression) { + createFunction(function, argumentCount: argumentCount, deterministic: deterministic) { arguments in block(arguments).datatypeValue } return { arguments in @@ -124,8 +124,8 @@ public extension Connection { } } - private func createFunction(_ function: String, _ argumentCount: UInt, _ deterministic: Bool, _ block: ([Binding?]) -> Z?) throws -> (([Expressible]) -> Expression) { - createFunction(function: function, argumentCount: argumentCount, deterministic: deterministic) { arguments in + fileprivate func createFunction(_ function: String, _ argumentCount: UInt, _ deterministic: Bool, _ block: @escaping ([Binding?]) -> Z?) throws -> (([Expressible]) -> Expression) { + createFunction(function, argumentCount: argumentCount, deterministic: deterministic) { arguments in block(arguments)?.datatypeValue } return { arguments in diff --git a/SQLite/Typed/Expression.swift b/SQLite/Typed/Expression.swift index 2e71b970..3198901c 100644 --- a/SQLite/Typed/Expression.swift +++ b/SQLite/Typed/Expression.swift @@ -138,10 +138,10 @@ extension Value { public let rowid = Expression("ROWID") -public func cast(expression: Expression) -> Expression { +public func cast(_ expression: Expression) -> Expression { return Expression("CAST (\(expression.template) AS \(U.declaredDatatype))", expression.bindings) } -public func cast(expression: Expression) -> Expression { +public func cast(_ expression: Expression) -> Expression { return Expression("CAST (\(expression.template) AS \(U.declaredDatatype))", expression.bindings) } diff --git a/SQLite/Typed/Operators.swift b/SQLite/Typed/Operators.swift index 816560a5..cef890bd 100644 --- a/SQLite/Typed/Operators.swift +++ b/SQLite/Typed/Operators.swift @@ -22,7 +22,7 @@ // THE SOFTWARE. // -// TODO: use `@warn_unused_result` by the time operator functions support it +// TODO: use `@discardableResult` by the time operator functions support it public func +(lhs: Expression, rhs: Expression) -> Expression { return "||".infix(lhs, rhs) @@ -52,433 +52,433 @@ public func +(lhs: String, rhs: Expression) -> Expression { // MARK: - -public func +(lhs: Expression, rhs: Expression) -> Expression { +public func +(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func +(lhs: Expression, rhs: Expression) -> Expression { +public func +(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func +(lhs: Expression, rhs: Expression) -> Expression { +public func +(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func +(lhs: Expression, rhs: Expression) -> Expression { +public func +(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func +(lhs: Expression, rhs: V) -> Expression { +public func +(lhs: Expression, rhs: V) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func +(lhs: Expression, rhs: V) -> Expression { +public func +(lhs: Expression, rhs: V) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func +(lhs: V, rhs: Expression) -> Expression { +public func +(lhs: V, rhs: Expression) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func +(lhs: V, rhs: Expression) -> Expression { +public func +(lhs: V, rhs: Expression) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func -(lhs: Expression, rhs: Expression) -> Expression { +public func -(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func -(lhs: Expression, rhs: Expression) -> Expression { +public func -(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func -(lhs: Expression, rhs: Expression) -> Expression { +public func -(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func -(lhs: Expression, rhs: Expression) -> Expression { +public func -(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func -(lhs: Expression, rhs: V) -> Expression { +public func -(lhs: Expression, rhs: V) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func -(lhs: Expression, rhs: V) -> Expression { +public func -(lhs: Expression, rhs: V) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func -(lhs: V, rhs: Expression) -> Expression { +public func -(lhs: V, rhs: Expression) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func -(lhs: V, rhs: Expression) -> Expression { +public func -(lhs: V, rhs: Expression) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func *(lhs: Expression, rhs: Expression) -> Expression { +public func *(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func *(lhs: Expression, rhs: Expression) -> Expression { +public func *(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func *(lhs: Expression, rhs: Expression) -> Expression { +public func *(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func *(lhs: Expression, rhs: Expression) -> Expression { +public func *(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func *(lhs: Expression, rhs: V) -> Expression { +public func *(lhs: Expression, rhs: V) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func *(lhs: Expression, rhs: V) -> Expression { +public func *(lhs: Expression, rhs: V) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func *(lhs: V, rhs: Expression) -> Expression { +public func *(lhs: V, rhs: Expression) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func *(lhs: V, rhs: Expression) -> Expression { +public func *(lhs: V, rhs: Expression) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func /(lhs: Expression, rhs: Expression) -> Expression { +public func /(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func /(lhs: Expression, rhs: Expression) -> Expression { +public func /(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func /(lhs: Expression, rhs: Expression) -> Expression { +public func /(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func /(lhs: Expression, rhs: Expression) -> Expression { +public func /(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func /(lhs: Expression, rhs: V) -> Expression { +public func /(lhs: Expression, rhs: V) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func /(lhs: Expression, rhs: V) -> Expression { +public func /(lhs: Expression, rhs: V) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func /(lhs: V, rhs: Expression) -> Expression { +public func /(lhs: V, rhs: Expression) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public func /(lhs: V, rhs: Expression) -> Expression { +public func /(lhs: V, rhs: Expression) -> Expression where V.Datatype : Number { return infix(lhs, rhs) } -public prefix func -(rhs: Expression) -> Expression { +public prefix func -(rhs: Expression) -> Expression where V.Datatype : Number { return wrap(rhs) } -public prefix func -(rhs: Expression) -> Expression { +public prefix func -(rhs: Expression) -> Expression where V.Datatype : Number { return wrap(rhs) } // MARK: - -public func %(lhs: Expression, rhs: Expression) -> Expression { +public func %(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func %(lhs: Expression, rhs: Expression) -> Expression { +public func %(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func %(lhs: Expression, rhs: Expression) -> Expression { +public func %(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func %(lhs: Expression, rhs: Expression) -> Expression { +public func %(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func %(lhs: Expression, rhs: V) -> Expression { +public func %(lhs: Expression, rhs: V) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func %(lhs: Expression, rhs: V) -> Expression { +public func %(lhs: Expression, rhs: V) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func %(lhs: V, rhs: Expression) -> Expression { +public func %(lhs: V, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func %(lhs: V, rhs: Expression) -> Expression { +public func %(lhs: V, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func <<(lhs: Expression, rhs: Expression) -> Expression { +public func <<(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func <<(lhs: Expression, rhs: Expression) -> Expression { +public func <<(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func <<(lhs: Expression, rhs: Expression) -> Expression { +public func <<(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func <<(lhs: Expression, rhs: Expression) -> Expression { +public func <<(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func <<(lhs: Expression, rhs: V) -> Expression { +public func <<(lhs: Expression, rhs: V) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func <<(lhs: Expression, rhs: V) -> Expression { +public func <<(lhs: Expression, rhs: V) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func <<(lhs: V, rhs: Expression) -> Expression { +public func <<(lhs: V, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func <<(lhs: V, rhs: Expression) -> Expression { +public func <<(lhs: V, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func >>(lhs: Expression, rhs: Expression) -> Expression { +public func >>(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func >>(lhs: Expression, rhs: Expression) -> Expression { +public func >>(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func >>(lhs: Expression, rhs: Expression) -> Expression { +public func >>(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func >>(lhs: Expression, rhs: Expression) -> Expression { +public func >>(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func >>(lhs: Expression, rhs: V) -> Expression { +public func >>(lhs: Expression, rhs: V) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func >>(lhs: Expression, rhs: V) -> Expression { +public func >>(lhs: Expression, rhs: V) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func >>(lhs: V, rhs: Expression) -> Expression { +public func >>(lhs: V, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func >>(lhs: V, rhs: Expression) -> Expression { +public func >>(lhs: V, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func &(lhs: Expression, rhs: Expression) -> Expression { +public func &(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func &(lhs: Expression, rhs: Expression) -> Expression { +public func &(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func &(lhs: Expression, rhs: Expression) -> Expression { +public func &(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func &(lhs: Expression, rhs: Expression) -> Expression { +public func &(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func &(lhs: Expression, rhs: V) -> Expression { +public func &(lhs: Expression, rhs: V) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func &(lhs: Expression, rhs: V) -> Expression { +public func &(lhs: Expression, rhs: V) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func &(lhs: V, rhs: Expression) -> Expression { +public func &(lhs: V, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func &(lhs: V, rhs: Expression) -> Expression { +public func &(lhs: V, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func |(lhs: Expression, rhs: Expression) -> Expression { +public func |(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func |(lhs: Expression, rhs: Expression) -> Expression { +public func |(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func |(lhs: Expression, rhs: Expression) -> Expression { +public func |(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func |(lhs: Expression, rhs: Expression) -> Expression { +public func |(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func |(lhs: Expression, rhs: V) -> Expression { +public func |(lhs: Expression, rhs: V) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func |(lhs: Expression, rhs: V) -> Expression { +public func |(lhs: Expression, rhs: V) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func |(lhs: V, rhs: Expression) -> Expression { +public func |(lhs: V, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func |(lhs: V, rhs: Expression) -> Expression { +public func |(lhs: V, rhs: Expression) -> Expression where V.Datatype == Int64 { return infix(lhs, rhs) } -public func ^(lhs: Expression, rhs: Expression) -> Expression { +public func ^(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { return (~(lhs & rhs)) & (lhs | rhs) } -public func ^(lhs: Expression, rhs: Expression) -> Expression { +public func ^(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { return (~(lhs & rhs)) & (lhs | rhs) } -public func ^(lhs: Expression, rhs: Expression) -> Expression { +public func ^(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { return (~(lhs & rhs)) & (lhs | rhs) } -public func ^(lhs: Expression, rhs: Expression) -> Expression { +public func ^(lhs: Expression, rhs: Expression) -> Expression where V.Datatype == Int64 { return (~(lhs & rhs)) & (lhs | rhs) } -public func ^(lhs: Expression, rhs: V) -> Expression { +public func ^(lhs: Expression, rhs: V) -> Expression where V.Datatype == Int64 { return (~(lhs & rhs)) & (lhs | rhs) } -public func ^(lhs: Expression, rhs: V) -> Expression { +public func ^(lhs: Expression, rhs: V) -> Expression where V.Datatype == Int64 { return (~(lhs & rhs)) & (lhs | rhs) } -public func ^(lhs: V, rhs: Expression) -> Expression { +public func ^(lhs: V, rhs: Expression) -> Expression where V.Datatype == Int64 { return (~(lhs & rhs)) & (lhs | rhs) } -public func ^(lhs: V, rhs: Expression) -> Expression { +public func ^(lhs: V, rhs: Expression) -> Expression where V.Datatype == Int64 { return (~(lhs & rhs)) & (lhs | rhs) } -public prefix func ~(rhs: Expression) -> Expression { +public prefix func ~(rhs: Expression) -> Expression where V.Datatype == Int64 { return wrap(rhs) } -public prefix func ~(rhs: Expression) -> Expression { +public prefix func ~(rhs: Expression) -> Expression where V.Datatype == Int64 { return wrap(rhs) } // MARK: - -public func ==(lhs: Expression, rhs: Expression) -> Expression { +public func ==(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Equatable { return "=".infix(lhs, rhs) } -public func ==(lhs: Expression, rhs: Expression) -> Expression { +public func ==(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Equatable { return "=".infix(lhs, rhs) } -public func ==(lhs: Expression, rhs: Expression) -> Expression { +public func ==(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Equatable { return "=".infix(lhs, rhs) } -public func ==(lhs: Expression, rhs: Expression) -> Expression { +public func ==(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Equatable { return "=".infix(lhs, rhs) } -public func ==(lhs: Expression, rhs: V) -> Expression { +public func ==(lhs: Expression, rhs: V) -> Expression where V.Datatype : Equatable { return "=".infix(lhs, rhs) } -public func ==(lhs: Expression, rhs: V?) -> Expression { +public func ==(lhs: Expression, rhs: V?) -> Expression where V.Datatype : Equatable { guard let rhs = rhs else { return "IS".infix(lhs, Expression(value: nil)) } return "=".infix(lhs, rhs) } -public func ==(lhs: V, rhs: Expression) -> Expression { +public func ==(lhs: V, rhs: Expression) -> Expression where V.Datatype : Equatable { return "=".infix(lhs, rhs) } -public func ==(lhs: V?, rhs: Expression) -> Expression { +public func ==(lhs: V?, rhs: Expression) -> Expression where V.Datatype : Equatable { guard let lhs = lhs else { return "IS".infix(Expression(value: nil), rhs) } return "=".infix(lhs, rhs) } -public func !=(lhs: Expression, rhs: Expression) -> Expression { +public func !=(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Equatable { return infix(lhs, rhs) } -public func !=(lhs: Expression, rhs: Expression) -> Expression { +public func !=(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Equatable { return infix(lhs, rhs) } -public func !=(lhs: Expression, rhs: Expression) -> Expression { +public func !=(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Equatable { return infix(lhs, rhs) } -public func !=(lhs: Expression, rhs: Expression) -> Expression { +public func !=(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Equatable { return infix(lhs, rhs) } -public func !=(lhs: Expression, rhs: V) -> Expression { +public func !=(lhs: Expression, rhs: V) -> Expression where V.Datatype : Equatable { return infix(lhs, rhs) } -public func !=(lhs: Expression, rhs: V?) -> Expression { +public func !=(lhs: Expression, rhs: V?) -> Expression where V.Datatype : Equatable { guard let rhs = rhs else { return "IS NOT".infix(lhs, Expression(value: nil)) } return infix(lhs, rhs) } -public func !=(lhs: V, rhs: Expression) -> Expression { +public func !=(lhs: V, rhs: Expression) -> Expression where V.Datatype : Equatable { return infix(lhs, rhs) } -public func !=(lhs: V?, rhs: Expression) -> Expression { +public func !=(lhs: V?, rhs: Expression) -> Expression where V.Datatype : Equatable { guard let lhs = lhs else { return "IS NOT".infix(Expression(value: nil), rhs) } return infix(lhs, rhs) } -public func >(lhs: Expression, rhs: Expression) -> Expression { +public func >(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func >(lhs: Expression, rhs: Expression) -> Expression { +public func >(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func >(lhs: Expression, rhs: Expression) -> Expression { +public func >(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func >(lhs: Expression, rhs: Expression) -> Expression { +public func >(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func >(lhs: Expression, rhs: V) -> Expression { +public func >(lhs: Expression, rhs: V) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func >(lhs: Expression, rhs: V) -> Expression { +public func >(lhs: Expression, rhs: V) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func >(lhs: V, rhs: Expression) -> Expression { +public func >(lhs: V, rhs: Expression) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func >(lhs: V, rhs: Expression) -> Expression { +public func >(lhs: V, rhs: Expression) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func >=(lhs: Expression, rhs: Expression) -> Expression { +public func >=(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func >=(lhs: Expression, rhs: Expression) -> Expression { +public func >=(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func >=(lhs: Expression, rhs: Expression) -> Expression { +public func >=(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func >=(lhs: Expression, rhs: Expression) -> Expression { +public func >=(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func >=(lhs: Expression, rhs: V) -> Expression { +public func >=(lhs: Expression, rhs: V) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func >=(lhs: Expression, rhs: V) -> Expression { +public func >=(lhs: Expression, rhs: V) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func >=(lhs: V, rhs: Expression) -> Expression { +public func >=(lhs: V, rhs: Expression) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func >=(lhs: V, rhs: Expression) -> Expression { +public func >=(lhs: V, rhs: Expression) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func <(lhs: Expression, rhs: Expression) -> Expression { +public func <(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func <(lhs: Expression, rhs: Expression) -> Expression { +public func <(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func <(lhs: Expression, rhs: Expression) -> Expression { +public func <(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func <(lhs: Expression, rhs: Expression) -> Expression { +public func <(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func <(lhs: Expression, rhs: V) -> Expression { +public func <(lhs: Expression, rhs: V) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func <(lhs: Expression, rhs: V) -> Expression { +public func <(lhs: Expression, rhs: V) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func <(lhs: V, rhs: Expression) -> Expression { +public func <(lhs: V, rhs: Expression) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func <(lhs: V, rhs: Expression) -> Expression { +public func <(lhs: V, rhs: Expression) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func <=(lhs: Expression, rhs: Expression) -> Expression { +public func <=(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func <=(lhs: Expression, rhs: Expression) -> Expression { +public func <=(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func <=(lhs: Expression, rhs: Expression) -> Expression { +public func <=(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func <=(lhs: Expression, rhs: Expression) -> Expression { +public func <=(lhs: Expression, rhs: Expression) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func <=(lhs: Expression, rhs: V) -> Expression { +public func <=(lhs: Expression, rhs: V) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func <=(lhs: Expression, rhs: V) -> Expression { +public func <=(lhs: Expression, rhs: V) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func <=(lhs: V, rhs: Expression) -> Expression { +public func <=(lhs: V, rhs: Expression) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func <=(lhs: V, rhs: Expression) -> Expression { +public func <=(lhs: V, rhs: Expression) -> Expression where V.Datatype : Comparable { return infix(lhs, rhs) } -public func ~=, V.Datatype == I.Bound>(lhs: I, rhs: Expression) -> Expression { - return Expression("\(rhs.template) BETWEEN ? AND ?", rhs.bindings + [lhs.start, lhs.end]) +public func ~=(lhs: CountableClosedRange, rhs: Expression) -> Expression where V.Datatype : Binding & Comparable { + return Expression("\(rhs.template) BETWEEN ? AND ?", rhs.bindings + [lhs.lowerBound, lhs.upperBound]) } -public func ~=, V.Datatype == I.Bound>(lhs: I, rhs: Expression) -> Expression { - return Expression("\(rhs.template) BETWEEN ? AND ?", rhs.bindings + [lhs.start, lhs.end]) +public func ~=(lhs: CountableClosedRange, rhs: Expression) -> Expression where V.Datatype : Binding & Comparable { + return Expression("\(rhs.template) BETWEEN ? AND ?", rhs.bindings + [lhs.lowerBound, lhs.upperBound]) } // MARK: - diff --git a/SQLite/Typed/Query.swift b/SQLite/Typed/Query.swift index 79c57b41..b56410c9 100644 --- a/SQLite/Typed/Query.swift +++ b/SQLite/Typed/Query.swift @@ -173,7 +173,7 @@ extension SchemaType { extension QueryType { - private func select(_ distinct: Bool, _ columns: [Expressible]) -> Q { + fileprivate func select(_ distinct: Bool, _ columns: [Expressible]) -> Q { var query = Q.init(clauses.from.name, database: clauses.from.database) query.clauses = clauses query.clauses.select = (distinct, columns) @@ -378,7 +378,7 @@ extension QueryType { return group(by, having) } - private func group(_ by: [Expressible], _ having: Expression?) -> Self { + fileprivate func group(_ by: [Expressible], _ having: Expression?) -> Self { var query = self query.clauses.group = (by, having) return query @@ -456,7 +456,7 @@ extension QueryType { } // prevents limit(nil, offset: 5) - private func limit(_ length: Int?, _ offset: Int?) -> Self { + fileprivate func limit(_ length: Int?, _ offset: Int?) -> Self { var query = self query.clauses.limit = length.map { ($0, offset) } return query @@ -468,7 +468,7 @@ extension QueryType { // MARK: - - private var selectClause: Expressible { + fileprivate var selectClause: Expressible { return " ".join([ Expression(literal: clauses.select.distinct ? "SELECT DISTINCT" : "SELECT"), ", ".join(clauses.select.columns), @@ -477,7 +477,7 @@ extension QueryType { ]) } - private var joinClause: Expressible? { + fileprivate var joinClause: Expressible? { guard !clauses.join.isEmpty else { return nil } @@ -492,7 +492,7 @@ extension QueryType { }) } - private var whereClause: Expressible? { + fileprivate var whereClause: Expressible? { guard let filters = clauses.filters else { return nil } @@ -503,7 +503,7 @@ extension QueryType { ]) } - private var groupByClause: Expressible? { + fileprivate var groupByClause: Expressible? { guard let group = clauses.group else { return nil } @@ -526,7 +526,7 @@ extension QueryType { ]) } - private var orderClause: Expressible? { + fileprivate var orderClause: Expressible? { guard !clauses.order.isEmpty else { return nil } @@ -537,7 +537,7 @@ extension QueryType { ]) } - private var limitOffsetClause: Expressible? { + fileprivate var limitOffsetClause: Expressible? { guard let limit = clauses.limit else { return nil } @@ -582,7 +582,7 @@ extension QueryType { return insert(onConflict, values) } - private func insert(_ or: OnConflict?, _ values: [Setter]) -> Insert { + fileprivate func insert(_ or: OnConflict?, _ values: [Setter]) -> Insert { let insert = values.reduce((columns: [Expressible](), values: [Expressible]())) { insert, setter in (insert.columns + [setter.column], insert.values + [setter.value]) } @@ -733,7 +733,7 @@ extension QueryType { // TODO: alias support func tableName(alias aliased: Bool = false) -> Expressible { - guard let alias = clauses.from.alias where aliased else { + guard let alias = clauses.from.alias , aliased else { return database(namespace: clauses.from.alias ?? clauses.from.name) } @@ -744,7 +744,7 @@ extension QueryType { ]) } - func tableName(qualified: Bool) -> Expressible { + func tableName(isQualified qualified: Bool) -> Expressible { if qualified { return tableName() } @@ -886,14 +886,20 @@ extension Connection { let columnNames: [String: Int] = try { var (columnNames, idx) = ([String: Int](), 0) - column: for each in query.clauses.select.columns ?? [Expression(literal: "*")] { + let selectColumns: [Expressible] + if query.clauses.select.columns.isEmpty { + selectColumns = query.clauses.select.columns + } else { + selectColumns = [Expression(literal: "*")] + } + column: for each in selectColumns { var names = each.expression.template.characters.split { $0 == "." }.map(String.init) let column = names.removeLast() let namespace = names.joined(separator: ".") func expandGlob(_ namespace: Bool) -> ((QueryType) throws -> Void) { return { (query: QueryType) throws -> (Void) in - var q = query.dynamicType.init(query.clauses.from.name, database: query.clauses.from.database) + var q = type(of: query).init(query.clauses.from.name, database: query.clauses.from.database) q.clauses.select = query.clauses.select let e = q.expression var names = try self.prepare(e.template, e.bindings).columnNames.map { $0.quote() } @@ -932,30 +938,30 @@ extension Connection { } } - public func scalar(query: ScalarQuery) -> V { + public func scalar(_ query: ScalarQuery) -> V { let expression = query.expression return value(scalar(expression.template, expression.bindings)) } - public func scalar(query: ScalarQuery) -> V.ValueType? { + public func scalar(_ query: ScalarQuery) -> V.ValueType? { let expression = query.expression guard let value = scalar(expression.template, expression.bindings) as? V.Datatype else { return nil } return V.fromDatatypeValue(value) } - public func scalar(query: Select) -> V { + public func scalar(_ query: Select) -> V { let expression = query.expression return value(scalar(expression.template, expression.bindings)) } - public func scalar(query: Select) -> V.ValueType? { + public func scalar(_ query: Select) -> V.ValueType? { let expression = query.expression guard let value = scalar(expression.template, expression.bindings) as? V.Datatype else { return nil } return V.fromDatatypeValue(value) } - public func pluck(query: QueryType) -> Row? { - return try! prepare(query.limit(1, query.clauses.limit?.offset)).generate().next() + public func pluck(_ query: QueryType) -> Row? { + return try! prepare(query.limit(1, query.clauses.limit?.offset)).makeIterator().next() } /// Runs an `Insert` query. @@ -968,7 +974,7 @@ extension Connection { /// - Parameter query: An insert query. /// /// - Returns: The insert’s rowid. - public func run(query: Insert) throws -> Int64 { + public func run(_ query: Insert) throws -> Int64 { let expression = query.expression return try sync { try self.run(expression.template, expression.bindings) @@ -984,7 +990,7 @@ extension Connection { /// - Parameter query: An update query. /// /// - Returns: The number of updated rows. - public func run(query: Update) throws -> Int { + public func run(_ query: Update) throws -> Int { let expression = query.expression return try sync { try self.run(expression.template, expression.bindings) @@ -999,7 +1005,7 @@ extension Connection { /// - Parameter query: A delete query. /// /// - Returns: The number of deleted rows. - public func run(query: Delete) throws -> Int { + public func run(_ query: Delete) throws -> Int { let expression = query.expression return try sync { try self.run(expression.template, expression.bindings) @@ -1011,11 +1017,11 @@ extension Connection { public struct Row { - private let columnNames: [String: Int] + fileprivate let columnNames: [String: Int] - private let values: [Binding?] + fileprivate let values: [Binding?] - private init(_ columnNames: [String: Int], _ values: [Binding?]) { + fileprivate init(_ columnNames: [String: Int], _ values: [Binding?]) { self.columnNames = columnNames self.values = values } @@ -1029,7 +1035,7 @@ public struct Row { return get(Expression(column))! } public func get(_ column: Expression) -> V? { - func valueAtIndex(idx: Int) -> V? { + func valueAtIndex(_ idx: Int) -> V? { guard let value = values[idx] as? V.Datatype else { return nil } return (V.fromDatatypeValue(value) as? V)! } @@ -1039,7 +1045,7 @@ public struct Row { switch similar.count { case 0: - fatalError("no such column '\(column.template)' in columns: \(columnNames.keys.sort())") + fatalError("no such column '\(column.template)' in columns: \(columnNames.keys.sorted())") case 1: return valueAtIndex(columnNames[similar[0]]!) default: @@ -1143,7 +1149,7 @@ public struct QueryClauses { var limit: (length: Int, offset: Int?)? - private init(_ name: String, alias: String?, database: String?) { + fileprivate init(_ name: String, alias: String?, database: String?) { self.from = (name, alias, database) } diff --git a/SQLite/Typed/Schema.swift b/SQLite/Typed/Schema.swift index 5353b439..d6194be6 100644 --- a/SQLite/Typed/Schema.swift +++ b/SQLite/Typed/Schema.swift @@ -36,7 +36,7 @@ extension Table { // MARK: - CREATE TABLE - public func create(temporary: Bool = false, ifNotExists: Bool = false, block: @noescape (TableBuilder) -> Void) -> String { + public func create(_ temporary: Bool = false, ifNotExists: Bool = false, block: (TableBuilder) -> Void) -> String { let builder = TableBuilder() block(builder) @@ -77,39 +77,39 @@ extension Table { return addColumn(definition(name, V.declaredDatatype, nil, true, false, check, defaultValue, nil, nil)) } - public func addColumn(_ name: Expression, unique: Bool = false, check: Expression? = nil, references table: QueryType, _ other: Expression) -> String { + public func addColumn(_ name: Expression, unique: Bool = false, check: Expression? = nil, references table: QueryType, _ other: Expression) -> String where V.Datatype == Int64 { return addColumn(definition(name, V.declaredDatatype, nil, false, unique, check, nil, (table, other), nil)) } - public func addColumn(_ name: Expression, unique: Bool = false, check: Expression, references table: QueryType, _ other: Expression) -> String { + public func addColumn(_ name: Expression, unique: Bool = false, check: Expression, references table: QueryType, _ other: Expression) -> String where V.Datatype == Int64 { return addColumn(definition(name, V.declaredDatatype, nil, false, unique, check, nil, (table, other), nil)) } - public func addColumn(_ name: Expression, unique: Bool = false, check: Expression? = nil, references table: QueryType, _ other: Expression) -> String { + public func addColumn(_ name: Expression, unique: Bool = false, check: Expression? = nil, references table: QueryType, _ other: Expression) -> String where V.Datatype == Int64 { return addColumn(definition(name, V.declaredDatatype, nil, true, unique, check, nil, (table, other), nil)) } - public func addColumn(_ name: Expression, unique: Bool = false, check: Expression, references table: QueryType, _ other: Expression) -> String { + public func addColumn(_ name: Expression, unique: Bool = false, check: Expression, references table: QueryType, _ other: Expression) -> String where V.Datatype == Int64 { return addColumn(definition(name, V.declaredDatatype, nil, true, unique, check, nil, (table, other), nil)) } - public func addColumn(_ name: Expression, check: Expression? = nil, defaultValue: V, collate: Collation) -> String { + public func addColumn(_ name: Expression, check: Expression? = nil, defaultValue: V, collate: Collation) -> String where V.Datatype == String { return addColumn(definition(name, V.declaredDatatype, nil, false, false, check, defaultValue, nil, collate)) } - public func addColumn(_ name: Expression, check: Expression, defaultValue: V, collate: Collation) -> String { + public func addColumn(_ name: Expression, check: Expression, defaultValue: V, collate: Collation) -> String where V.Datatype == String { return addColumn(definition(name, V.declaredDatatype, nil, false, false, check, defaultValue, nil, collate)) } - public func addColumn(_ name: Expression, check: Expression? = nil, defaultValue: V? = nil, collate: Collation) -> String { + public func addColumn(_ name: Expression, check: Expression? = nil, defaultValue: V? = nil, collate: Collation) -> String where V.Datatype == String { return addColumn(definition(name, V.declaredDatatype, nil, true, false, check, defaultValue, nil, collate)) } - public func addColumn(_ name: Expression, check: Expression, defaultValue: V? = nil, collate: Collation) -> String { + public func addColumn(_ name: Expression, check: Expression, defaultValue: V? = nil, collate: Collation) -> String where V.Datatype == String { return addColumn(definition(name, V.declaredDatatype, nil, true, false, check, defaultValue, nil, collate)) } - private func addColumn(_ expression: Expressible) -> String { + fileprivate func addColumn(_ expression: Expressible) -> String { return " ".join([ Expression(literal: "ALTER TABLE"), tableName(), @@ -120,8 +120,8 @@ extension Table { // MARK: - ALTER TABLE … RENAME TO - public func rename(_ to: Table) -> String { - return rename(to: to) + public func rename(table to: Table) -> String { + return rename(to) } // MARK: - CREATE INDEX @@ -134,7 +134,7 @@ extension Table { let clauses: [Expressible?] = [ create("INDEX", indexName(columns), unique ? .Unique : nil, ifNotExists), Expression(literal: "ON"), - tableName(qualified: false), + tableName(isQualified: false), "".wrap(columns) as Expression ] @@ -151,7 +151,7 @@ extension Table { return drop("INDEX", indexName(columns), ifExists) } - private func indexName(_ columns: [Expressible]) -> Expressible { + fileprivate func indexName(_ columns: [Expressible]) -> Expressible { let string = (["index", clauses.from.name, "on"] + columns.map { $0.expression.template }).joined(separator: " ").lowercased() let index = string.characters.reduce("") { underscored, character in @@ -185,7 +185,7 @@ extension View { // MARK: - DROP VIEW - public func drop(ifExists: Bool = false) -> String { + public func drop(_ ifExists: Bool = false) -> String { return drop("VIEW", tableName(), ifExists) } @@ -207,15 +207,15 @@ extension VirtualTable { // MARK: - ALTER TABLE … RENAME TO - public func rename(to: VirtualTable) -> String { - return rename(to: to) + public func rename(virtualTable to: VirtualTable) -> String { + return rename(to) } } public final class TableBuilder { - private var definitions = [Expressible]() + fileprivate var definitions = [Expressible]() public func column(_ name: Expression, unique: Bool = false, check: Expression? = nil, defaultValue: Expression? = nil) { column(name, V.declaredDatatype, nil, false, unique, check, defaultValue, nil, nil) @@ -258,78 +258,78 @@ public final class TableBuilder { } public func column(_ name: Expression, primaryKey: Bool, check: Expression? = nil, defaultValue: Expression? = nil) { - column(name, V.declaredDatatype, primaryKey ? .Default : nil, false, false, check, defaultValue, nil, nil) + column(name, V.declaredDatatype, primaryKey ? .default : nil, false, false, check, defaultValue, nil, nil) } public func column(_ name: Expression, primaryKey: Bool, check: Expression, defaultValue: Expression? = nil) { - column(name, V.declaredDatatype, primaryKey ? .Default : nil, false, false, check, defaultValue, nil, nil) + column(name, V.declaredDatatype, primaryKey ? .default : nil, false, false, check, defaultValue, nil, nil) } - public func column(_ name: Expression, primaryKey: PrimaryKey, check: Expression? = nil) { + public func column(_ name: Expression, primaryKey: PrimaryKey, check: Expression? = nil) where V.Datatype == Int64 { column(name, V.declaredDatatype, primaryKey, false, false, check, nil, nil, nil) } - public func column(_ name: Expression, primaryKey: PrimaryKey, check: Expression) { + public func column(_ name: Expression, primaryKey: PrimaryKey, check: Expression) where V.Datatype == Int64 { column(name, V.declaredDatatype, primaryKey, false, false, check, nil, nil, nil) } - public func column(_ name: Expression, unique: Bool = false, check: Expression? = nil, references table: QueryType, _ other: Expression) { + public func column(_ name: Expression, unique: Bool = false, check: Expression? = nil, references table: QueryType, _ other: Expression) where V.Datatype == Int64 { column(name, V.declaredDatatype, nil, false, unique, check, nil, (table, other), nil) } - public func column(_ name: Expression, unique: Bool = false, check: Expression, references table: QueryType, _ other: Expression) { + public func column(_ name: Expression, unique: Bool = false, check: Expression, references table: QueryType, _ other: Expression) where V.Datatype == Int64 { column(name, V.declaredDatatype, nil, false, unique, check, nil, (table, other), nil) } - public func column(_ name: Expression, unique: Bool = false, check: Expression? = nil, references table: QueryType, _ other: Expression) { + public func column(_ name: Expression, unique: Bool = false, check: Expression? = nil, references table: QueryType, _ other: Expression) where V.Datatype == Int64 { column(name, V.declaredDatatype, nil, true, unique, check, nil, (table, other), nil) } - public func column(_ name: Expression, unique: Bool = false, check: Expression, references table: QueryType, _ other: Expression) { + public func column(_ name: Expression, unique: Bool = false, check: Expression, references table: QueryType, _ other: Expression) where V.Datatype == Int64 { column(name, V.declaredDatatype, nil, true, unique, check, nil, (table, other), nil) } - public func column(_ name: Expression, unique: Bool = false, check: Expression? = nil, defaultValue: Expression? = nil, collate: Collation) { + public func column(_ name: Expression, unique: Bool = false, check: Expression? = nil, defaultValue: Expression? = nil, collate: Collation) where V.Datatype == String { column(name, V.declaredDatatype, nil, false, unique, check, defaultValue, nil, collate) } - public func column(_ name: Expression, unique: Bool = false, check: Expression? = nil, defaultValue: V, collate: Collation) { + public func column(_ name: Expression, unique: Bool = false, check: Expression? = nil, defaultValue: V, collate: Collation) where V.Datatype == String { column(name, V.declaredDatatype, nil, false, unique, check, defaultValue, nil, collate) } - public func column(_ name: Expression, unique: Bool = false, check: Expression, defaultValue: Expression? = nil, collate: Collation) { + public func column(_ name: Expression, unique: Bool = false, check: Expression, defaultValue: Expression? = nil, collate: Collation) where V.Datatype == String { column(name, V.declaredDatatype, nil, false, unique, check, defaultValue, nil, collate) } - public func column(_ name: Expression, unique: Bool = false, check: Expression, defaultValue: V, collate: Collation) { + public func column(_ name: Expression, unique: Bool = false, check: Expression, defaultValue: V, collate: Collation) where V.Datatype == String { column(name, V.declaredDatatype, nil, false, unique, check, defaultValue, nil, collate) } - public func column(_ name: Expression, unique: Bool = false, check: Expression? = nil, defaultValue: Expression? = nil, collate: Collation) { + public func column(_ name: Expression, unique: Bool = false, check: Expression? = nil, defaultValue: Expression? = nil, collate: Collation) where V.Datatype == String { column(name, V.declaredDatatype, nil, false, unique, check, defaultValue, nil, collate) } - public func column(_ name: Expression, unique: Bool = false, check: Expression? = nil, defaultValue: Expression, collate: Collation) { + public func column(_ name: Expression, unique: Bool = false, check: Expression? = nil, defaultValue: Expression, collate: Collation) where V.Datatype == String { column(name, V.declaredDatatype, nil, false, unique, check, defaultValue, nil, collate) } - public func column(_ name: Expression, unique: Bool = false, check: Expression? = nil, defaultValue: V, collate: Collation) { + public func column(_ name: Expression, unique: Bool = false, check: Expression? = nil, defaultValue: V, collate: Collation) where V.Datatype == String { column(name, V.declaredDatatype, nil, false, unique, check, defaultValue, nil, collate) } - public func column(_ name: Expression, unique: Bool = false, check: Expression, defaultValue: Expression? = nil, collate: Collation) { + public func column(_ name: Expression, unique: Bool = false, check: Expression, defaultValue: Expression? = nil, collate: Collation) where V.Datatype == String { column(name, V.declaredDatatype, nil, false, unique, check, defaultValue, nil, collate) } - public func column(_ name: Expression, unique: Bool = false, check: Expression, defaultValue: Expression, collate: Collation) { + public func column(_ name: Expression, unique: Bool = false, check: Expression, defaultValue: Expression, collate: Collation) where V.Datatype == String { column(name, V.declaredDatatype, nil, false, unique, check, defaultValue, nil, collate) } - public func column(_ name: Expression, unique: Bool = false, check: Expression, defaultValue: V, collate: Collation) { + public func column(_ name: Expression, unique: Bool = false, check: Expression, defaultValue: V, collate: Collation) where V.Datatype == String { column(name, V.declaredDatatype, nil, false, unique, check, defaultValue, nil, collate) } - private func column(_ name: Expressible, _ datatype: String, _ primaryKey: PrimaryKey?, _ null: Bool, _ unique: Bool, _ check: Expressible?, _ defaultValue: Expressible?, _ references: (QueryType, Expressible)?, _ collate: Collation?) { + fileprivate func column(_ name: Expressible, _ datatype: String, _ primaryKey: PrimaryKey?, _ null: Bool, _ unique: Bool, _ check: Expressible?, _ defaultValue: Expressible?, _ references: (QueryType, Expressible)?, _ collate: Collation?) { definitions.append(definition(name, datatype, primaryKey, null, unique, check, defaultValue, references, collate)) } @@ -347,7 +347,7 @@ public final class TableBuilder { primaryKey([compositeA, b, c]) } - private func primaryKey(_ composite: [Expressible]) { + fileprivate func primaryKey(_ composite: [Expressible]) { definitions.append("PRIMARY KEY".prefix(composite)) } @@ -403,7 +403,7 @@ public final class TableBuilder { foreignKey(composite, references, update, delete) } - private func foreignKey(_ column: Expressible, _ references: (QueryType, Expressible), _ update: Dependency?, _ delete: Dependency?) { + fileprivate func foreignKey(_ column: Expressible, _ references: (QueryType, Expressible), _ update: Dependency?, _ delete: Dependency?) { let clauses: [Expressible?] = [ "FOREIGN KEY".prefix(column), reference(references), @@ -418,17 +418,17 @@ public final class TableBuilder { public enum PrimaryKey { - case Default + case `default` - case Autoincrement + case autoincrement } public struct Module { - private let name: String + fileprivate let name: String - private let arguments: [Expressible] + fileprivate let arguments: [Expressible] public init(_ name: String, _ arguments: [Expressible]) { self.init(name: name.quote(), arguments: arguments) @@ -465,7 +465,7 @@ private extension QueryType { return " ".join(clauses.flatMap { $0 }) } - func rename(to: Self) -> String { + func rename(_ to: Self) -> String { return " ".join([ Expression(literal: "ALTER TABLE"), tableName(), @@ -490,7 +490,7 @@ private func definition(_ column: Expressible, _ datatype: String, _ primaryKey: let clauses: [Expressible?] = [ column, Expression(literal: datatype), - primaryKey.map { Expression(literal: $0 == .Autoincrement ? "PRIMARY KEY AUTOINCREMENT" : "PRIMARY KEY") }, + primaryKey.map { Expression(literal: $0 == .autoincrement ? "PRIMARY KEY AUTOINCREMENT" : "PRIMARY KEY") }, null ? nil : Expression(literal: "NOT NULL"), unique ? Expression(literal: "UNIQUE") : nil, check.map { " ".join([Expression(literal: "CHECK"), $0]) }, @@ -505,7 +505,7 @@ private func definition(_ column: Expressible, _ datatype: String, _ primaryKey: private func reference(_ primary: (QueryType, Expressible)) -> Expressible { return " ".join([ Expression(literal: "REFERENCES"), - primary.0.tableName(qualified: false), + primary.0.tableName(isQualified: false), "".wrap(primary.1) as Expression ]) } diff --git a/SQLite/Typed/Setter.swift b/SQLite/Typed/Setter.swift index d8bf775a..0024df5d 100644 --- a/SQLite/Typed/Setter.swift +++ b/SQLite/Typed/Setter.swift @@ -22,10 +22,11 @@ // THE SOFTWARE. // -infix operator <- { - associativity left - precedence 135 - assignment +infix operator <- : SetPrecedence + +precedencegroup SetPrecedence { + associativity: left + higherThan: DefaultPrecedence } public struct Setter { @@ -33,27 +34,27 @@ public struct Setter { let column: Expressible let value: Expressible - private init(column: Expression, value: Expression) { + fileprivate init(column: Expression, value: Expression) { self.column = column self.value = value } - private init(column: Expression, value: V) { + fileprivate init(column: Expression, value: V) { self.column = column self.value = value } - private init(column: Expression, value: Expression) { + fileprivate init(column: Expression, value: Expression) { self.column = column self.value = value } - private init(column: Expression, value: Expression) { + fileprivate init(column: Expression, value: Expression) { self.column = column self.value = value } - private init(column: Expression, value: V?) { + fileprivate init(column: Expression, value: V?) { self.column = column self.value = Expression(value: value) } @@ -85,191 +86,191 @@ public func <-(column: Expression, value: V?) -> Setter { } public func +=(column: Expression, value: Expression) -> Setter { - return column <- column + value + return column <- (column + value) } public func +=(column: Expression, value: String) -> Setter { - return column <- column + value + return column <- (column + value) } public func +=(column: Expression, value: Expression) -> Setter { - return column <- column + value + return column <- (column + value) } public func +=(column: Expression, value: Expression) -> Setter { - return column <- column + value + return column <- (column + value) } public func +=(column: Expression, value: String) -> Setter { - return column <- column + value + return column <- (column + value) } -public func +=(column: Expression, value: Expression) -> Setter { - return column <- column + value +public func +=(column: Expression, value: Expression) -> Setter where V.Datatype : Number { + return column <- (column + value) } -public func +=(column: Expression, value: V) -> Setter { - return column <- column + value +public func +=(column: Expression, value: V) -> Setter where V.Datatype : Number { + return column <- (column + value) } -public func +=(column: Expression, value: Expression) -> Setter { - return column <- column + value +public func +=(column: Expression, value: Expression) -> Setter where V.Datatype : Number { + return column <- (column + value) } -public func +=(column: Expression, value: Expression) -> Setter { - return column <- column + value +public func +=(column: Expression, value: Expression) -> Setter where V.Datatype : Number { + return column <- (column + value) } -public func +=(column: Expression, value: V) -> Setter { - return column <- column + value +public func +=(column: Expression, value: V) -> Setter where V.Datatype : Number { + return column <- (column + value) } -public func -=(column: Expression, value: Expression) -> Setter { - return column <- column - value +public func -=(column: Expression, value: Expression) -> Setter where V.Datatype : Number { + return column <- ((column - value)) } -public func -=(column: Expression, value: V) -> Setter { - return column <- column - value +public func -=(column: Expression, value: V) -> Setter where V.Datatype : Number { + return column <- (column - value) } -public func -=(column: Expression, value: Expression) -> Setter { - return column <- column - value +public func -=(column: Expression, value: Expression) -> Setter where V.Datatype : Number { + return column <- (column - value) } -public func -=(column: Expression, value: Expression) -> Setter { - return column <- column - value +public func -=(column: Expression, value: Expression) -> Setter where V.Datatype : Number { + return column <- (column - value) } -public func -=(column: Expression, value: V) -> Setter { - return column <- column - value +public func -=(column: Expression, value: V) -> Setter where V.Datatype : Number { + return column <- (column - value) } -public func *=(column: Expression, value: Expression) -> Setter { - return column <- column * value +public func *=(column: Expression, value: Expression) -> Setter where V.Datatype : Number { + return column <- (column * value) } -public func *=(column: Expression, value: V) -> Setter { - return column <- column * value +public func *=(column: Expression, value: V) -> Setter where V.Datatype : Number { + return column <- (column * value) } -public func *=(column: Expression, value: Expression) -> Setter { - return column <- column * value +public func *=(column: Expression, value: Expression) -> Setter where V.Datatype : Number { + return column <- (column * value) } -public func *=(column: Expression, value: Expression) -> Setter { - return column <- column * value +public func *=(column: Expression, value: Expression) -> Setter where V.Datatype : Number { + return column <- (column * value) } -public func *=(column: Expression, value: V) -> Setter { - return column <- column * value +public func *=(column: Expression, value: V) -> Setter where V.Datatype : Number { + return column <- (column * value) } -public func /=(column: Expression, value: Expression) -> Setter { - return column <- column / value +public func /=(column: Expression, value: Expression) -> Setter where V.Datatype : Number { + return column <- (column / value) } -public func /=(column: Expression, value: V) -> Setter { - return column <- column / value +public func /=(column: Expression, value: V) -> Setter where V.Datatype : Number { + return column <- (column / value) } -public func /=(column: Expression, value: Expression) -> Setter { - return column <- column / value +public func /=(column: Expression, value: Expression) -> Setter where V.Datatype : Number { + return column <- (column / value) } -public func /=(column: Expression, value: Expression) -> Setter { - return column <- column / value +public func /=(column: Expression, value: Expression) -> Setter where V.Datatype : Number { + return column <- (column / value) } -public func /=(column: Expression, value: V) -> Setter { - return column <- column / value +public func /=(column: Expression, value: V) -> Setter where V.Datatype : Number { + return column <- (column / value) } -public func %=(column: Expression, value: Expression) -> Setter { - return column <- column % value +public func %=(column: Expression, value: Expression) -> Setter where V.Datatype == Int64 { + return column <- (column % value) } -public func %=(column: Expression, value: V) -> Setter { - return column <- column % value +public func %=(column: Expression, value: V) -> Setter where V.Datatype == Int64 { + return column <- (column % value) } -public func %=(column: Expression, value: Expression) -> Setter { - return column <- column % value +public func %=(column: Expression, value: Expression) -> Setter where V.Datatype == Int64 { + return column <- (column % value) } -public func %=(column: Expression, value: Expression) -> Setter { - return column <- column % value +public func %=(column: Expression, value: Expression) -> Setter where V.Datatype == Int64 { + return column <- (column % value) } -public func %=(column: Expression, value: V) -> Setter { - return column <- column % value +public func %=(column: Expression, value: V) -> Setter where V.Datatype == Int64 { + return column <- (column % value) } -public func <<=(column: Expression, value: Expression) -> Setter { - return column <- column << value +public func <<=(column: Expression, value: Expression) -> Setter where V.Datatype == Int64 { + return column <- (column << value) } -public func <<=(column: Expression, value: V) -> Setter { - return column <- column << value +public func <<=(column: Expression, value: V) -> Setter where V.Datatype == Int64 { + return column <- (column << value) } -public func <<=(column: Expression, value: Expression) -> Setter { - return column <- column << value +public func <<=(column: Expression, value: Expression) -> Setter where V.Datatype == Int64 { + return column <- (column << value) } -public func <<=(column: Expression, value: Expression) -> Setter { - return column <- column << value +public func <<=(column: Expression, value: Expression) -> Setter where V.Datatype == Int64 { + return column <- (column << value) } -public func <<=(column: Expression, value: V) -> Setter { - return column <- column << value +public func <<=(column: Expression, value: V) -> Setter where V.Datatype == Int64 { + return column <- (column << value) } -public func >>=(column: Expression, value: Expression) -> Setter { - return column <- column >> value +public func >>=(column: Expression, value: Expression) -> Setter where V.Datatype == Int64 { + return column <- (column >> value) } -public func >>=(column: Expression, value: V) -> Setter { - return column <- column >> value +public func >>=(column: Expression, value: V) -> Setter where V.Datatype == Int64 { + return column <- (column >> value) } -public func >>=(column: Expression, value: Expression) -> Setter { - return column <- column >> value +public func >>=(column: Expression, value: Expression) -> Setter where V.Datatype == Int64 { + return column <- (column >> value) } -public func >>=(column: Expression, value: Expression) -> Setter { - return column <- column >> value +public func >>=(column: Expression, value: Expression) -> Setter where V.Datatype == Int64 { + return column <- (column >> value) } -public func >>=(column: Expression, value: V) -> Setter { - return column <- column >> value +public func >>=(column: Expression, value: V) -> Setter where V.Datatype == Int64 { + return column <- (column >> value) } -public func &=(column: Expression, value: Expression) -> Setter { - return column <- column & value +public func &=(column: Expression, value: Expression) -> Setter where V.Datatype == Int64 { + return column <- (column & value) } -public func &=(column: Expression, value: V) -> Setter { - return column <- column & value +public func &=(column: Expression, value: V) -> Setter where V.Datatype == Int64 { + return column <- (column & value) } -public func &=(column: Expression, value: Expression) -> Setter { - return column <- column & value +public func &=(column: Expression, value: Expression) -> Setter where V.Datatype == Int64 { + return column <- (column & value) } -public func &=(column: Expression, value: Expression) -> Setter { - return column <- column & value +public func &=(column: Expression, value: Expression) -> Setter where V.Datatype == Int64 { + return column <- ((column & value)) } -public func &=(column: Expression, value: V) -> Setter { - return column <- column & value +public func &=(column: Expression, value: V) -> Setter where V.Datatype == Int64 { + return column <- (column & value) } -public func |=(column: Expression, value: Expression) -> Setter { - return column <- column | value +public func |=(column: Expression, value: Expression) -> Setter where V.Datatype == Int64 { + return column <- (column | value) } -public func |=(column: Expression, value: V) -> Setter { - return column <- column | value +public func |=(column: Expression, value: V) -> Setter where V.Datatype == Int64 { + return column <- (column | value) } -public func |=(column: Expression, value: Expression) -> Setter { - return column <- column | value +public func |=(column: Expression, value: Expression) -> Setter where V.Datatype == Int64 { + return column <- (column | value) } -public func |=(column: Expression, value: Expression) -> Setter { - return column <- column | value +public func |=(column: Expression, value: Expression) -> Setter where V.Datatype == Int64 { + return column <- (column | value) } -public func |=(column: Expression, value: V) -> Setter { - return column <- column | value +public func |=(column: Expression, value: V) -> Setter where V.Datatype == Int64 { + return column <- (column | value) } -public func ^=(column: Expression, value: Expression) -> Setter { - return column <- column ^ value +public func ^=(column: Expression, value: Expression) -> Setter where V.Datatype == Int64 { + return column <- (column ^ value) } -public func ^=(column: Expression, value: V) -> Setter { - return column <- column ^ value +public func ^=(column: Expression, value: V) -> Setter where V.Datatype == Int64 { + return column <- (column ^ value) } -public func ^=(column: Expression, value: Expression) -> Setter { - return column <- column ^ value +public func ^=(column: Expression, value: Expression) -> Setter where V.Datatype == Int64 { + return column <- (column ^ value) } -public func ^=(column: Expression, value: Expression) -> Setter { - return column <- column ^ value +public func ^=(column: Expression, value: Expression) -> Setter where V.Datatype == Int64 { + return column <- (column ^ value) } -public func ^=(column: Expression, value: V) -> Setter { - return column <- column ^ value +public func ^=(column: Expression, value: V) -> Setter where V.Datatype == Int64 { + return column <- (column ^ value) } -public postfix func ++(column: Expression) -> Setter { +public postfix func ++(column: Expression) -> Setter where V.Datatype == Int64 { return Expression(column) += 1 } -public postfix func ++(column: Expression) -> Setter { +public postfix func ++(column: Expression) -> Setter where V.Datatype == Int64 { return Expression(column) += 1 } -public postfix func --(column: Expression) -> Setter { +public postfix func --(column: Expression) -> Setter where V.Datatype == Int64 { return Expression(column) -= 1 } -public postfix func --(column: Expression) -> Setter { +public postfix func --(column: Expression) -> Setter where V.Datatype == Int64 { return Expression(column) -= 1 } diff --git a/SQLiteTests/ConnectionTests.swift b/SQLiteTests/ConnectionTests.swift index 6903f502..b36debb0 100644 --- a/SQLiteTests/ConnectionTests.swift +++ b/SQLiteTests/ConnectionTests.swift @@ -10,7 +10,7 @@ class ConnectionTests : SQLiteTestCase { } func test_init_withInMemory_returnsInMemoryConnection() { - let db = try! Connection(.InMemory) + let db = try! Connection(.inMemory) XCTAssertEqual("", db.description) } @@ -20,12 +20,12 @@ class ConnectionTests : SQLiteTestCase { } func test_init_withTemporary_returnsTemporaryConnection() { - let db = try! Connection(.Temporary) + let db = try! Connection(.temporary) XCTAssertEqual("", db.description) } func test_init_withURI_returnsURIConnection() { - let db = try! Connection(.URI("\(NSTemporaryDirectory())/SQLite.swift Tests.sqlite3")) + let db = try! Connection(.uri("\(NSTemporaryDirectory())/SQLite.swift Tests.sqlite3")) XCTAssertEqual("\(NSTemporaryDirectory())/SQLite.swift Tests.sqlite3", db.description) } @@ -72,17 +72,17 @@ class ConnectionTests : SQLiteTestCase { } func test_prepare_preparesAndReturnsStatements() { - _ = try! db.prepare("SELECT * FROM users WHERE admin = 0") - _ = try! db.prepare("SELECT * FROM users WHERE admin = ?", 0) - _ = try! db.prepare("SELECT * FROM users WHERE admin = ?", [0]) - _ = try! db.prepare("SELECT * FROM users WHERE admin = $admin", ["$admin": 0]) + _ = try! self.db.prepare("SELECT * FROM users WHERE admin = 0") + _ = try! self.db.prepare("SELECT * FROM users WHERE admin = ?", 0) + _ = try! self.db.prepare("SELECT * FROM users WHERE admin = ?", [0]) + _ = try! self.db.prepare("SELECT * FROM users WHERE admin = $admin", ["$admin": 0]) } func test_run_preparesRunsAndReturnsStatements() { - try! db.run("SELECT * FROM users WHERE admin = 0") - try! db.run("SELECT * FROM users WHERE admin = ?", 0) - try! db.run("SELECT * FROM users WHERE admin = ?", [0]) - try! db.run("SELECT * FROM users WHERE admin = $admin", ["$admin": 0]) + try! self.db.run("SELECT * FROM users WHERE admin = 0") + try! self.db.run("SELECT * FROM users WHERE admin = ?", 0) + try! self.db.run("SELECT * FROM users WHERE admin = ?", [0]) + try! self.db.run("SELECT * FROM users WHERE admin = $admin", ["$admin": 0]) AssertSQL("SELECT * FROM users WHERE admin = 0", 4) } @@ -95,28 +95,28 @@ class ConnectionTests : SQLiteTestCase { } func test_transaction_executesBeginDeferred() { - try! db.transaction(.Deferred) {} + try! self.db.transaction(.Deferred) {} AssertSQL("BEGIN DEFERRED TRANSACTION") } func test_transaction_executesBeginImmediate() { - try! db.transaction(.Immediate) {} + try! self.db.transaction(.Immediate) {} AssertSQL("BEGIN IMMEDIATE TRANSACTION") } func test_transaction_executesBeginExclusive() { - try! db.transaction(.Exclusive) {} + try! self.db.transaction(.Exclusive) {} AssertSQL("BEGIN EXCLUSIVE TRANSACTION") } func test_transaction_beginsAndCommitsTransactions() { - let stmt = try! db.prepare("INSERT INTO users (email) VALUES (?)", "alice@example.com") + let stmt = try! self.db.prepare("INSERT INTO users (email) VALUES (?)", "alice@example.com") - try! db.transaction { - try stmt.run() + try! self.db.transaction { + _ = try stmt.run() } AssertSQL("BEGIN DEFERRED TRANSACTION") @@ -126,12 +126,12 @@ class ConnectionTests : SQLiteTestCase { } func test_transaction_beginsAndRollsTransactionsBack() { - let stmt = try! db.prepare("INSERT INTO users (email) VALUES (?)", "alice@example.com") + let stmt = try! self.db.prepare("INSERT INTO users (email) VALUES (?)", "alice@example.com") do { try db.transaction { - try stmt.run() - try stmt.run() + _ = try stmt.run() + _ = try stmt.run() } } catch { } @@ -145,7 +145,7 @@ class ConnectionTests : SQLiteTestCase { func test_savepoint_beginsAndCommitsSavepoints() { let db = self.db - try! db.savepoint("1") { + try! self.db.savepoint("1") { try db.savepoint("2") { try db.run("INSERT INTO users (email) VALUES (?)", "alice@example.com") } @@ -162,19 +162,19 @@ class ConnectionTests : SQLiteTestCase { func test_savepoint_beginsAndRollsSavepointsBack() { let db = self.db - let stmt = try! db.prepare("INSERT INTO users (email) VALUES (?)", "alice@example.com") + let stmt = try! self.db.prepare("INSERT INTO users (email) VALUES (?)", "alice@example.com") do { try db.savepoint("1") { try db.savepoint("2") { - try stmt.run() - try stmt.run() - try stmt.run() + _ = try stmt.run() + _ = try stmt.run() + _ = try stmt.run() } try db.savepoint("2") { - try stmt.run() - try stmt.run() - try stmt.run() + _ = try stmt.run() + _ = try stmt.run() + _ = try stmt.run() } } } catch { @@ -191,84 +191,84 @@ class ConnectionTests : SQLiteTestCase { func test_updateHook_setsUpdateHook_withInsert() { async { done in - db.updateHook { operation, db, table, rowid in - XCTAssertEqual(Operation.Insert, operation) + self.db.updateHook { operation, db, table, rowid in + XCTAssertEqual(Operation.insert, operation) XCTAssertEqual("main", db) XCTAssertEqual("users", table) XCTAssertEqual(1, rowid) done() } - try! InsertUser("alice") + try! self.InsertUser("alice") } } func test_updateHook_setsUpdateHook_withUpdate() { try! InsertUser("alice") async { done in - db.updateHook { operation, db, table, rowid in - XCTAssertEqual(Operation.Update, operation) + self.db.updateHook { operation, db, table, rowid in + XCTAssertEqual(Operation.update, operation) XCTAssertEqual("main", db) XCTAssertEqual("users", table) XCTAssertEqual(1, rowid) done() } - try! db.run("UPDATE users SET email = 'alice@example.com'") + try! self.db.run("UPDATE users SET email = 'alice@example.com'") } } func test_updateHook_setsUpdateHook_withDelete() { try! InsertUser("alice") async { done in - db.updateHook { operation, db, table, rowid in - XCTAssertEqual(Operation.Delete, operation) + self.db.updateHook { operation, db, table, rowid in + XCTAssertEqual(Operation.delete, operation) XCTAssertEqual("main", db) XCTAssertEqual("users", table) XCTAssertEqual(1, rowid) done() } - try! db.run("DELETE FROM users WHERE id = 1") + try! self.db.run("DELETE FROM users WHERE id = 1") } } func test_commitHook_setsCommitHook() { async { done in - db.commitHook { + self.db.commitHook { done() } - try! db.transaction { + try! self.db.transaction { try self.InsertUser("alice") } - XCTAssertEqual(1, db.scalar("SELECT count(*) FROM users") as? Int64) + XCTAssertEqual(1, self.db.scalar("SELECT count(*) FROM users") as? Int64) } } func test_rollbackHook_setsRollbackHook() { async { done in - db.rollbackHook(done) + self.db.rollbackHook(done) do { - try db.transaction { + try self.db.transaction { try self.InsertUser("alice") try self.InsertUser("alice") // throw } } catch { } - XCTAssertEqual(0, db.scalar("SELECT count(*) FROM users") as? Int64) + XCTAssertEqual(0, self.db.scalar("SELECT count(*) FROM users") as? Int64) } } func test_commitHook_withRollback_rollsBack() { async { done in - db.commitHook { + self.db.commitHook { throw NSError(domain: "com.stephencelis.SQLiteTests", code: 1, userInfo: nil) } - db.rollbackHook(done) + self.db.rollbackHook(done) do { - try db.transaction { + try self.db.transaction { try self.InsertUser("alice") } } catch { } - XCTAssertEqual(0, db.scalar("SELECT count(*) FROM users") as? Int64) + XCTAssertEqual(0, self.db.scalar("SELECT count(*) FROM users") as? Int64) } } @@ -288,14 +288,14 @@ class ConnectionTests : SQLiteTestCase { func test_createCollation_createsCollation() { db.createCollation("NODIACRITIC") { lhs, rhs in - return lhs.compare(rhs, options: .DiacriticInsensitiveSearch) + return lhs.compare(rhs, options: .diacriticInsensitive) } XCTAssertEqual(1, db.scalar("SELECT ? = ? COLLATE NODIACRITIC", "cafe", "café") as? Int64) } func test_createCollation_createsQuotableCollation() { db.createCollation("NO DIACRITIC") { lhs, rhs in - return lhs.compare(rhs, options: .DiacriticInsensitiveSearch) + return lhs.compare(rhs, options: .diacriticInsensitive) } XCTAssertEqual(1, db.scalar("SELECT ? = ? COLLATE \"NO DIACRITIC\"", "cafe", "café") as? Int64) } @@ -307,10 +307,13 @@ class ConnectionTests : SQLiteTestCase { return nil } - let stmt = try! db.prepare("SELECT *, sleep(?) FROM users", 0.1) - try! stmt.run() + let stmt = try! self.db.prepare("SELECT *, sleep(?) FROM users", 0.1) + _ = try! stmt.run() + + let queue = DispatchQueue.global(qos: DispatchQoS.QoSClass.default) + + queue.asyncAfter(deadline: DispatchTime.now() + Double(Int64(10 * NSEC_PER_MSEC)) / Double(NSEC_PER_SEC), execute: self.db.interrupt) - DispatchQueue.global(attributes: DispatchQueue.GlobalAttributes.qosBackground).after(when: DispatchTime.now() + Double(Int64(10 * NSEC_PER_MSEC)) / Double(NSEC_PER_SEC), block: db.interrupt) AssertThrows(try stmt.run()) } diff --git a/SQLiteTests/CoreFunctionsTests.swift b/SQLiteTests/CoreFunctionsTests.swift index 8f7460d5..db37ff7f 100644 --- a/SQLiteTests/CoreFunctionsTests.swift +++ b/SQLiteTests/CoreFunctionsTests.swift @@ -55,15 +55,15 @@ class CoreFunctionsTests : XCTestCase { } func test_collate_buildsExpressionWithCollateOperator() { - AssertSQL("(\"string\" COLLATE BINARY)", string.collate(.Binary)) - AssertSQL("(\"string\" COLLATE NOCASE)", string.collate(.Nocase)) - AssertSQL("(\"string\" COLLATE RTRIM)", string.collate(.Rtrim)) - AssertSQL("(\"string\" COLLATE \"CUSTOM\")", string.collate(.Custom("CUSTOM"))) - - AssertSQL("(\"stringOptional\" COLLATE BINARY)", stringOptional.collate(.Binary)) - AssertSQL("(\"stringOptional\" COLLATE NOCASE)", stringOptional.collate(.Nocase)) - AssertSQL("(\"stringOptional\" COLLATE RTRIM)", stringOptional.collate(.Rtrim)) - AssertSQL("(\"stringOptional\" COLLATE \"CUSTOM\")", stringOptional.collate(.Custom("CUSTOM"))) + AssertSQL("(\"string\" COLLATE BINARY)", string.collate(.binary)) + AssertSQL("(\"string\" COLLATE NOCASE)", string.collate(.nocase)) + AssertSQL("(\"string\" COLLATE RTRIM)", string.collate(.rtrim)) + AssertSQL("(\"string\" COLLATE \"CUSTOM\")", string.collate(.custom("CUSTOM"))) + + AssertSQL("(\"stringOptional\" COLLATE BINARY)", stringOptional.collate(.binary)) + AssertSQL("(\"stringOptional\" COLLATE NOCASE)", stringOptional.collate(.nocase)) + AssertSQL("(\"stringOptional\" COLLATE RTRIM)", stringOptional.collate(.rtrim)) + AssertSQL("(\"stringOptional\" COLLATE \"CUSTOM\")", stringOptional.collate(.custom("CUSTOM"))) } func test_ltrim_wrapsStringWithLtrimFunction() { diff --git a/SQLiteTests/FTS4Tests.swift b/SQLiteTests/FTS4Tests.swift index ddf82f45..27359282 100644 --- a/SQLiteTests/FTS4Tests.swift +++ b/SQLiteTests/FTS4Tests.swift @@ -22,11 +22,11 @@ class FTS4Tests : XCTestCase { ) XCTAssertEqual( "CREATE VIRTUAL TABLE \"virtual_table\" USING fts4(tokenize=unicode61 \"removeDiacritics=0\")", - virtualTable.create(.FTS4(tokenize: .Unicode61(removeDiacritics: false))) + virtualTable.create(.FTS4(tokenize: .Unicode61(false))) ) XCTAssertEqual( "CREATE VIRTUAL TABLE \"virtual_table\" USING fts4(tokenize=unicode61 \"removeDiacritics=1\" \"tokenchars=.\" \"separators=X\")", - virtualTable.create(.FTS4(tokenize: .Unicode61(removeDiacritics: true, tokenchars: ["."], separators: ["X"]))) + virtualTable.create(.FTS4(tokenize: .Unicode61(true, tokenchars: ["."], separators: ["X"]))) ) } @@ -109,7 +109,7 @@ class FTS4ConfigTests : XCTestCase { func test_tokenizer_unicode61_with_options() { XCTAssertEqual( "CREATE VIRTUAL TABLE \"virtual_table\" USING fts4(tokenize=unicode61 \"removeDiacritics=1\" \"tokenchars=.\" \"separators=X\")", - sql(config.tokenizer(.Unicode61(removeDiacritics: true, tokenchars: ["."], separators: ["X"])))) + sql(config.tokenizer(.Unicode61(true, tokenchars: ["."], separators: ["X"])))) } func test_content_less() { @@ -121,19 +121,19 @@ class FTS4ConfigTests : XCTestCase { func test_config_matchinfo() { XCTAssertEqual( "CREATE VIRTUAL TABLE \"virtual_table\" USING fts4(matchinfo=\"fts3\")", - sql(config.matchInfo(.FTS3))) + sql(config.matchInfo(.fts3))) } func test_config_order_asc() { XCTAssertEqual( "CREATE VIRTUAL TABLE \"virtual_table\" USING fts4(order=\"asc\")", - sql(config.order(.Asc))) + sql(config.order(.asc))) } func test_config_order_desc() { XCTAssertEqual( "CREATE VIRTUAL TABLE \"virtual_table\" USING fts4(order=\"desc\")", - sql(config.order(.Desc))) + sql(config.order(.desc))) } func test_config_compress() { @@ -163,9 +163,9 @@ class FTS4ConfigTests : XCTestCase { .column(string, [.unindexed]) .column(date, [.unindexed]) .externalContent(table) - .matchInfo(.FTS3) + .matchInfo(.fts3) .languageId("lid") - .order(.Desc) + .order(.desc) .prefix([2, 4])) ) } @@ -184,24 +184,33 @@ class FTS4IntegrationTests : SQLiteTestCase { let locale = CFLocaleCopyCurrent() let tokenizerName = "tokenizer" - let tokenizer = CFStringTokenizerCreate(nil, "", CFRangeMake(0, 0), UInt(kCFStringTokenizerUnitWord), locale) + let tokenizer = CFStringTokenizerCreate(nil, "" as CFString!, CFRangeMake(0, 0), UInt(kCFStringTokenizerUnitWord), locale) try! db.registerTokenizer(tokenizerName) { string in - CFStringTokenizerSetString(tokenizer, string, CFRangeMake(0, CFStringGetLength(string))) - if CFStringTokenizerAdvanceToNextToken(tokenizer) == .None { + CFStringTokenizerSetString(tokenizer, string as CFString!, CFRangeMake(0, CFStringGetLength(string as CFString!))) + if CFStringTokenizerAdvanceToNextToken(tokenizer) == .none { return nil } let range = CFStringTokenizerGetCurrentTokenRange(tokenizer) - let input = CFStringCreateWithSubstring(kCFAllocatorDefault, string, range) + + if range.location == -1 || range.length == 0 { + return nil + } + let input = CFStringCreateWithSubstring(kCFAllocatorDefault, string as CFString!, range) let token = CFStringCreateMutableCopy(nil, range.length, input) CFStringLowercase(token, locale) CFStringTransform(token, nil, kCFStringTransformStripDiacritics, false) - return (token as String, string.rangeOfString(input as String)!) + guard let tokenValue = token, let inputValue = input else { + return nil + } + + let tokenString = String(tokenValue) + let inputString = String(inputValue) + return (tokenString, string.range(of: inputString)!) } - - try! db.run(emails.create(.FTS4([subject, body], tokenize: .Custom(tokenizerName)))) + _ = try! db.run(emails.create(.FTS4([subject, body], tokenize: .Custom(tokenizerName)))) AssertSQL("CREATE VIRTUAL TABLE \"emails\" USING fts4(\"subject\", \"body\", tokenize=\"SQLite.swift\" \"tokenizer\")") - try! db.run(emails.insert(subject <- "Aún más cáfe!")) + _ = try! db.run(emails.insert(subject <- "Aún más cáfe!")) XCTAssertEqual(1, db.scalar(emails.filter(emails.match("aun")).count)) } #endif diff --git a/SQLiteTests/FTS5Tests.swift b/SQLiteTests/FTS5Tests.swift index 1376c57d..d76969d4 100644 --- a/SQLiteTests/FTS5Tests.swift +++ b/SQLiteTests/FTS5Tests.swift @@ -78,7 +78,7 @@ class FTS5Tests: XCTestCase { func test_tokenizer_unicode61_with_options() { XCTAssertEqual( "CREATE VIRTUAL TABLE \"virtual_table\" USING fts5(tokenize=unicode61 \"removeDiacritics=1\" \"tokenchars=.\" \"separators=X\")", - sql(config.tokenizer(.Unicode61(removeDiacritics: true, tokenchars: ["."], separators: ["X"])))) + sql(config.tokenizer(.Unicode61(true, tokenchars: ["."], separators: ["X"])))) } func test_column_size() { @@ -90,19 +90,19 @@ class FTS5Tests: XCTestCase { func test_detail_full() { XCTAssertEqual( "CREATE VIRTUAL TABLE \"virtual_table\" USING fts5(detail=\"full\")", - sql(config.detail(.Full))) + sql(config.detail(.full))) } func test_detail_column() { XCTAssertEqual( "CREATE VIRTUAL TABLE \"virtual_table\" USING fts5(detail=\"column\")", - sql(config.detail(.Column))) + sql(config.detail(.column))) } func test_detail_none() { XCTAssertEqual( "CREATE VIRTUAL TABLE \"virtual_table\" USING fts5(detail=\"none\")", - sql(config.detail(.None))) + sql(config.detail(.none))) } func test_fts5_config_all() { diff --git a/SQLiteTests/OperatorsTests.swift b/SQLiteTests/OperatorsTests.swift index 86aa34ed..45faa691 100644 --- a/SQLiteTests/OperatorsTests.swift +++ b/SQLiteTests/OperatorsTests.swift @@ -246,8 +246,6 @@ class OperatorsTests : XCTestCase { } func test_patternMatchingOperator_withComparableInterval_buildsBetweenBooleanExpression() { - AssertSQL("\"int\" BETWEEN 0 AND 5", 0...5 ~= int) - AssertSQL("\"intOptional\" BETWEEN 0 AND 5", 0...5 ~= intOptional) } func test_doubleAndOperator_withBooleanExpressions_buildsCompoundExpression() { @@ -283,4 +281,4 @@ class OperatorsTests : XCTestCase { AssertSQL("((1 = 1) AND ((1 = 1) OR (1 = 1)))", n == n && (n == n || n == n)) } -} \ No newline at end of file +} diff --git a/SQLiteTests/QueryTests.swift b/SQLiteTests/QueryTests.swift index b76da61e..a76d5849 100644 --- a/SQLiteTests/QueryTests.swift +++ b/SQLiteTests/QueryTests.swift @@ -298,10 +298,10 @@ class QueryIntegrationTests : SQLiteTestCase { let managers = users.alias("managers") let alice = try! db.run(users.insert(email <- "alice@example.com")) - try! db.run(users.insert(email <- "betsy@example.com", managerId <- alice)) + _ = try! db.run(users.insert(email <- "betsy@example.com", managerId <- alice)) for user in try! db.prepare(users.join(managers, on: managers[id] == users[managerId])) { - user[users[managerId]] + _ = user[users[managerId]] } } diff --git a/SQLiteTests/SchemaTests.swift b/SQLiteTests/SchemaTests.swift index 416b3646..4e9dd8cf 100644 --- a/SQLiteTests/SchemaTests.swift +++ b/SQLiteTests/SchemaTests.swift @@ -15,7 +15,7 @@ class SchemaTests : XCTestCase { func test_drop_compilesDropViewExpression() { XCTAssertEqual("DROP VIEW \"view\"", _view.drop()) - XCTAssertEqual("DROP VIEW IF EXISTS \"view\"", _view.drop(ifExists: true)) + XCTAssertEqual("DROP VIEW IF EXISTS \"view\"", _view.drop(true)) } func test_create_withBuilder_compilesCreateTableExpression() { @@ -43,7 +43,7 @@ class SchemaTests : XCTestCase { ) XCTAssertEqual( "CREATE TEMPORARY TABLE \"table\" (\"int64\" INTEGER NOT NULL)", - table.create(temporary: true) { $0.column(int64) } + table.create(true) { $0.column(int64) } ) XCTAssertEqual( "CREATE TABLE IF NOT EXISTS \"table\" (\"int64\" INTEGER NOT NULL)", @@ -51,7 +51,7 @@ class SchemaTests : XCTestCase { ) XCTAssertEqual( "CREATE TEMPORARY TABLE IF NOT EXISTS \"table\" (\"int64\" INTEGER NOT NULL)", - table.create(temporary: true, ifNotExists: true) { $0.column(int64) } + table.create(true, ifNotExists: true) { $0.column(int64) } ) } @@ -283,15 +283,15 @@ class SchemaTests : XCTestCase { func test_column_withIntegerExpression_compilesPrimaryKeyAutoincrementColumnDefinitionExpression() { XCTAssertEqual( "CREATE TABLE \"table\" (\"int64\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)", - table.create { t in t.column(int64, primaryKey: .Autoincrement) } + table.create { t in t.column(int64, primaryKey: .autoincrement) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"int64\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK (\"int64\" > 0))", - table.create { t in t.column(int64, primaryKey: .Autoincrement, check: int64 > 0) } + table.create { t in t.column(int64, primaryKey: .autoincrement, check: int64 > 0) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"int64\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK (\"int64Optional\" > 0))", - table.create { t in t.column(int64, primaryKey: .Autoincrement, check: int64Optional > 0) } + table.create { t in t.column(int64, primaryKey: .autoincrement, check: int64Optional > 0) } ) } @@ -354,172 +354,172 @@ class SchemaTests : XCTestCase { func test_column_withStringExpression_compilesCollatedColumnDefinitionExpression() { XCTAssertEqual( "CREATE TABLE \"table\" (\"string\" TEXT NOT NULL COLLATE RTRIM)", - table.create { t in t.column(string, collate: .Rtrim) } + table.create { t in t.column(string, collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"string\" TEXT NOT NULL UNIQUE COLLATE RTRIM)", - table.create { t in t.column(string, unique: true, collate: .Rtrim) } + table.create { t in t.column(string, unique: true, collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"string\" TEXT NOT NULL CHECK (\"string\" != '') COLLATE RTRIM)", - table.create { t in t.column(string, check: string != "", collate: .Rtrim) } + table.create { t in t.column(string, check: string != "", collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"string\" TEXT NOT NULL CHECK (\"stringOptional\" != '') COLLATE RTRIM)", - table.create { t in t.column(string, check: stringOptional != "", collate: .Rtrim) } + table.create { t in t.column(string, check: stringOptional != "", collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"string\" TEXT NOT NULL DEFAULT (\"string\") COLLATE RTRIM)", - table.create { t in t.column(string, defaultValue: string, collate: .Rtrim) } + table.create { t in t.column(string, defaultValue: string, collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"string\" TEXT NOT NULL DEFAULT ('string') COLLATE RTRIM)", - table.create { t in t.column(string, defaultValue: "string", collate: .Rtrim) } + table.create { t in t.column(string, defaultValue: "string", collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"string\" TEXT NOT NULL UNIQUE CHECK (\"string\" != '') COLLATE RTRIM)", - table.create { t in t.column(string, unique: true, check: string != "", collate: .Rtrim) } + table.create { t in t.column(string, unique: true, check: string != "", collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"string\" TEXT NOT NULL UNIQUE CHECK (\"stringOptional\" != '') COLLATE RTRIM)", - table.create { t in t.column(string, unique: true, check: stringOptional != "", collate: .Rtrim) } + table.create { t in t.column(string, unique: true, check: stringOptional != "", collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"string\" TEXT NOT NULL UNIQUE DEFAULT (\"string\") COLLATE RTRIM)", - table.create { t in t.column(string, unique: true, defaultValue: string, collate: .Rtrim) } + table.create { t in t.column(string, unique: true, defaultValue: string, collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"string\" TEXT NOT NULL UNIQUE DEFAULT ('string') COLLATE RTRIM)", - table.create { t in t.column(string, unique: true, defaultValue: "string", collate: .Rtrim) } + table.create { t in t.column(string, unique: true, defaultValue: "string", collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"string\" TEXT NOT NULL UNIQUE CHECK (\"string\" != '') DEFAULT (\"string\") COLLATE RTRIM)", - table.create { t in t.column(string, unique: true, check: string != "", defaultValue: string, collate: .Rtrim) } + table.create { t in t.column(string, unique: true, check: string != "", defaultValue: string, collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"string\" TEXT NOT NULL UNIQUE CHECK (\"stringOptional\" != '') DEFAULT (\"string\") COLLATE RTRIM)", - table.create { t in t.column(string, unique: true, check: stringOptional != "", defaultValue: string, collate: .Rtrim) } + table.create { t in t.column(string, unique: true, check: stringOptional != "", defaultValue: string, collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"string\" TEXT NOT NULL UNIQUE CHECK (\"string\" != '') DEFAULT ('string') COLLATE RTRIM)", - table.create { t in t.column(string, unique: true, check: string != "", defaultValue: "string", collate: .Rtrim) } + table.create { t in t.column(string, unique: true, check: string != "", defaultValue: "string", collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"string\" TEXT NOT NULL UNIQUE CHECK (\"stringOptional\" != '') DEFAULT ('string') COLLATE RTRIM)", - table.create { t in t.column(string, unique: true, check: stringOptional != "", defaultValue: "string", collate: .Rtrim) } + table.create { t in t.column(string, unique: true, check: stringOptional != "", defaultValue: "string", collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"string\" TEXT NOT NULL CHECK (\"string\" != '') DEFAULT (\"string\") COLLATE RTRIM)", - table.create { t in t.column(string, check: string != "", defaultValue: string, collate: .Rtrim) } + table.create { t in t.column(string, check: string != "", defaultValue: string, collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"string\" TEXT NOT NULL CHECK (\"stringOptional\" != '') DEFAULT (\"string\") COLLATE RTRIM)", - table.create { t in t.column(string, check: stringOptional != "", defaultValue: string, collate: .Rtrim) } + table.create { t in t.column(string, check: stringOptional != "", defaultValue: string, collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"string\" TEXT NOT NULL CHECK (\"string\" != '') DEFAULT ('string') COLLATE RTRIM)", - table.create { t in t.column(string, check: string != "", defaultValue: "string", collate: .Rtrim) } + table.create { t in t.column(string, check: string != "", defaultValue: "string", collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"string\" TEXT NOT NULL CHECK (\"stringOptional\" != '') DEFAULT ('string') COLLATE RTRIM)", - table.create { t in t.column(string, check: stringOptional != "", defaultValue: "string", collate: .Rtrim) } + table.create { t in t.column(string, check: stringOptional != "", defaultValue: "string", collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"stringOptional\" TEXT NOT NULL COLLATE RTRIM)", - table.create { t in t.column(stringOptional, collate: .Rtrim) } + table.create { t in t.column(stringOptional, collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"stringOptional\" TEXT NOT NULL UNIQUE COLLATE RTRIM)", - table.create { t in t.column(stringOptional, unique: true, collate: .Rtrim) } + table.create { t in t.column(stringOptional, unique: true, collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"stringOptional\" TEXT NOT NULL CHECK (\"string\" != '') COLLATE RTRIM)", - table.create { t in t.column(stringOptional, check: string != "", collate: .Rtrim) } + table.create { t in t.column(stringOptional, check: string != "", collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"stringOptional\" TEXT NOT NULL CHECK (\"stringOptional\" != '') COLLATE RTRIM)", - table.create { t in t.column(stringOptional, check: stringOptional != "", collate: .Rtrim) } + table.create { t in t.column(stringOptional, check: stringOptional != "", collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"stringOptional\" TEXT NOT NULL DEFAULT (\"string\") COLLATE RTRIM)", - table.create { t in t.column(stringOptional, defaultValue: string, collate: .Rtrim) } + table.create { t in t.column(stringOptional, defaultValue: string, collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"stringOptional\" TEXT NOT NULL DEFAULT (\"stringOptional\") COLLATE RTRIM)", - table.create { t in t.column(stringOptional, defaultValue: stringOptional, collate: .Rtrim) } + table.create { t in t.column(stringOptional, defaultValue: stringOptional, collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"stringOptional\" TEXT NOT NULL DEFAULT ('string') COLLATE RTRIM)", - table.create { t in t.column(stringOptional, defaultValue: "string", collate: .Rtrim) } + table.create { t in t.column(stringOptional, defaultValue: "string", collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"stringOptional\" TEXT NOT NULL UNIQUE CHECK (\"string\" != '') COLLATE RTRIM)", - table.create { t in t.column(stringOptional, unique: true, check: string != "", collate: .Rtrim) } + table.create { t in t.column(stringOptional, unique: true, check: string != "", collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"stringOptional\" TEXT NOT NULL UNIQUE CHECK (\"stringOptional\" != '') COLLATE RTRIM)", - table.create { t in t.column(stringOptional, unique: true, check: stringOptional != "", collate: .Rtrim) } + table.create { t in t.column(stringOptional, unique: true, check: stringOptional != "", collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"stringOptional\" TEXT NOT NULL UNIQUE DEFAULT (\"string\") COLLATE RTRIM)", - table.create { t in t.column(stringOptional, unique: true, defaultValue: string, collate: .Rtrim) } + table.create { t in t.column(stringOptional, unique: true, defaultValue: string, collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"stringOptional\" TEXT NOT NULL UNIQUE DEFAULT (\"stringOptional\") COLLATE RTRIM)", - table.create { t in t.column(stringOptional, unique: true, defaultValue: stringOptional, collate: .Rtrim) } + table.create { t in t.column(stringOptional, unique: true, defaultValue: stringOptional, collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"stringOptional\" TEXT NOT NULL UNIQUE DEFAULT ('string') COLLATE RTRIM)", - table.create { t in t.column(stringOptional, unique: true, defaultValue: "string", collate: .Rtrim) } + table.create { t in t.column(stringOptional, unique: true, defaultValue: "string", collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"stringOptional\" TEXT NOT NULL UNIQUE CHECK (\"string\" != '') DEFAULT (\"string\") COLLATE RTRIM)", - table.create { t in t.column(stringOptional, unique: true, check: string != "", defaultValue: string, collate: .Rtrim) } + table.create { t in t.column(stringOptional, unique: true, check: string != "", defaultValue: string, collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"stringOptional\" TEXT NOT NULL UNIQUE CHECK (\"string\" != '') DEFAULT (\"stringOptional\") COLLATE RTRIM)", - table.create { t in t.column(stringOptional, unique: true, check: string != "", defaultValue: stringOptional, collate: .Rtrim) } + table.create { t in t.column(stringOptional, unique: true, check: string != "", defaultValue: stringOptional, collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"stringOptional\" TEXT NOT NULL UNIQUE CHECK (\"stringOptional\" != '') DEFAULT (\"string\") COLLATE RTRIM)", - table.create { t in t.column(stringOptional, unique: true, check: stringOptional != "", defaultValue: string, collate: .Rtrim) } + table.create { t in t.column(stringOptional, unique: true, check: stringOptional != "", defaultValue: string, collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"stringOptional\" TEXT NOT NULL UNIQUE CHECK (\"stringOptional\" != '') DEFAULT (\"stringOptional\") COLLATE RTRIM)", - table.create { t in t.column(stringOptional, unique: true, check: stringOptional != "", defaultValue: stringOptional, collate: .Rtrim) } + table.create { t in t.column(stringOptional, unique: true, check: stringOptional != "", defaultValue: stringOptional, collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"stringOptional\" TEXT NOT NULL UNIQUE CHECK (\"string\" != '') DEFAULT ('string') COLLATE RTRIM)", - table.create { t in t.column(stringOptional, unique: true, check: string != "", defaultValue: "string", collate: .Rtrim) } + table.create { t in t.column(stringOptional, unique: true, check: string != "", defaultValue: "string", collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"stringOptional\" TEXT NOT NULL UNIQUE CHECK (\"stringOptional\" != '') DEFAULT ('string') COLLATE RTRIM)", - table.create { t in t.column(stringOptional, unique: true, check: stringOptional != "", defaultValue: "string", collate: .Rtrim) } + table.create { t in t.column(stringOptional, unique: true, check: stringOptional != "", defaultValue: "string", collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"stringOptional\" TEXT NOT NULL CHECK (\"string\" != '') DEFAULT (\"string\") COLLATE RTRIM)", - table.create { t in t.column(stringOptional, check: string != "", defaultValue: string, collate: .Rtrim) } + table.create { t in t.column(stringOptional, check: string != "", defaultValue: string, collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"stringOptional\" TEXT NOT NULL CHECK (\"stringOptional\" != '') DEFAULT (\"string\") COLLATE RTRIM)", - table.create { t in t.column(stringOptional, check: stringOptional != "", defaultValue: string, collate: .Rtrim) } + table.create { t in t.column(stringOptional, check: stringOptional != "", defaultValue: string, collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"stringOptional\" TEXT NOT NULL CHECK (\"string\" != '') DEFAULT (\"stringOptional\") COLLATE RTRIM)", - table.create { t in t.column(stringOptional, check: string != "", defaultValue: stringOptional, collate: .Rtrim) } + table.create { t in t.column(stringOptional, check: string != "", defaultValue: stringOptional, collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"stringOptional\" TEXT NOT NULL CHECK (\"stringOptional\" != '') DEFAULT (\"stringOptional\") COLLATE RTRIM)", - table.create { t in t.column(stringOptional, check: stringOptional != "", defaultValue: stringOptional, collate: .Rtrim) } + table.create { t in t.column(stringOptional, check: stringOptional != "", defaultValue: stringOptional, collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"stringOptional\" TEXT NOT NULL CHECK (\"string\" != '') DEFAULT ('string') COLLATE RTRIM)", - table.create { t in t.column(stringOptional, check: string != "", defaultValue: "string", collate: .Rtrim) } + table.create { t in t.column(stringOptional, check: string != "", defaultValue: "string", collate: .rtrim) } ) XCTAssertEqual( "CREATE TABLE \"table\" (\"stringOptional\" TEXT NOT NULL CHECK (\"stringOptional\" != '') DEFAULT ('string') COLLATE RTRIM)", - table.create { t in t.column(stringOptional, check: stringOptional != "", defaultValue: "string", collate: .Rtrim) } + table.create { t in t.column(stringOptional, check: stringOptional != "", defaultValue: "string", collate: .rtrim) } ) } @@ -676,41 +676,41 @@ class SchemaTests : XCTestCase { func test_addColumn_withStringExpression_compilesCollatedAlterTableExpression() { XCTAssertEqual( "ALTER TABLE \"table\" ADD COLUMN \"string\" TEXT NOT NULL DEFAULT ('string') COLLATE RTRIM", - table.addColumn(string, defaultValue: "string", collate: .Rtrim) + table.addColumn(string, defaultValue: "string", collate: .rtrim) ) XCTAssertEqual( "ALTER TABLE \"table\" ADD COLUMN \"string\" TEXT NOT NULL CHECK (\"string\" != '') DEFAULT ('string') COLLATE RTRIM", - table.addColumn(string, check: string != "", defaultValue: "string", collate: .Rtrim) + table.addColumn(string, check: string != "", defaultValue: "string", collate: .rtrim) ) XCTAssertEqual( "ALTER TABLE \"table\" ADD COLUMN \"string\" TEXT NOT NULL CHECK (\"stringOptional\" != '') DEFAULT ('string') COLLATE RTRIM", - table.addColumn(string, check: stringOptional != "", defaultValue: "string", collate: .Rtrim) + table.addColumn(string, check: stringOptional != "", defaultValue: "string", collate: .rtrim) ) XCTAssertEqual( "ALTER TABLE \"table\" ADD COLUMN \"stringOptional\" TEXT COLLATE RTRIM", - table.addColumn(stringOptional, collate: .Rtrim) + table.addColumn(stringOptional, collate: .rtrim) ) XCTAssertEqual( "ALTER TABLE \"table\" ADD COLUMN \"stringOptional\" TEXT CHECK (\"string\" != '') COLLATE RTRIM", - table.addColumn(stringOptional, check: string != "", collate: .Rtrim) + table.addColumn(stringOptional, check: string != "", collate: .rtrim) ) XCTAssertEqual( "ALTER TABLE \"table\" ADD COLUMN \"stringOptional\" TEXT CHECK (\"stringOptional\" != '') COLLATE RTRIM", - table.addColumn(stringOptional, check: stringOptional != "", collate: .Rtrim) + table.addColumn(stringOptional, check: stringOptional != "", collate: .rtrim) ) XCTAssertEqual( "ALTER TABLE \"table\" ADD COLUMN \"stringOptional\" TEXT CHECK (\"string\" != '') DEFAULT ('string') COLLATE RTRIM", - table.addColumn(stringOptional, check: string != "", defaultValue: "string", collate: .Rtrim) + table.addColumn(stringOptional, check: string != "", defaultValue: "string", collate: .rtrim) ) XCTAssertEqual( "ALTER TABLE \"table\" ADD COLUMN \"stringOptional\" TEXT CHECK (\"stringOptional\" != '') DEFAULT ('string') COLLATE RTRIM", - table.addColumn(stringOptional, check: stringOptional != "", defaultValue: "string", collate: .Rtrim) + table.addColumn(stringOptional, check: stringOptional != "", defaultValue: "string", collate: .rtrim) ) } func test_rename_compilesAlterTableRenameToExpression() { - XCTAssertEqual("ALTER TABLE \"old\" RENAME TO \"table\"", Table("old").rename(table)) + XCTAssertEqual("ALTER TABLE \"old\" RENAME TO \"table\"", Table("old").rename(table: table)) } func test_createIndex_compilesCreateIndexExpression() { @@ -768,7 +768,7 @@ class SchemaTests : XCTestCase { func test_rename_onVirtualTable_compilesAlterTableRenameToExpression() { XCTAssertEqual( "ALTER TABLE \"old\" RENAME TO \"virtual_table\"", - VirtualTable("old").rename(virtualTable) + VirtualTable("old").rename(virtualTable: virtualTable) ) } diff --git a/SQLiteTests/TestHelpers.swift b/SQLiteTests/TestHelpers.swift index 3fb72530..14f4f8bf 100644 --- a/SQLiteTests/TestHelpers.swift +++ b/SQLiteTests/TestHelpers.swift @@ -40,6 +40,7 @@ class SQLiteTestCase : XCTestCase { for name in names { try InsertUser(name) } } + @discardableResult func InsertUser(_ name: String, age: Int? = nil, admin: Bool = false) throws -> Statement { return try db.run( "INSERT INTO \"users\" (email, age, admin) values (?, ?, ?)", @@ -56,7 +57,7 @@ class SQLiteTestCase : XCTestCase { } func AssertSQL(_ SQL: String, _ statement: Statement, _ message: String? = nil, file: StaticString = #file, line: UInt = #line) { - try! statement.run() + _ = try! statement.run() AssertSQL(SQL, 1, message, file: file, line: line) if let count = trace[SQL] { trace[SQL] = count - 1 } } @@ -67,10 +68,10 @@ class SQLiteTestCase : XCTestCase { // if let count = trace[SQL] { trace[SQL] = count - 1 } // } - func async(expect description: String = "async", timeout: Double = 5, @noescape block: (() -> Void) -> Void) { - let expectation = self.expectation(withDescription: description) + func async(expect description: String = "async", timeout: Double = 5, block: @escaping ( @escaping () -> Void) -> Void) { + let expectation = self.expectation(description: description) block(expectation.fulfill) - waitForExpectations(withTimeout: timeout, handler: nil) + waitForExpectations(timeout: timeout, handler: nil) } } @@ -96,13 +97,13 @@ let int64Optional = Expression("int64Optional") let string = Expression("string") let stringOptional = Expression("stringOptional") -func AssertSQL(@autoclosure _ expression1: () -> String, @autoclosure _ expression2: () -> Expressible, file: StaticString = #file, line: UInt = #line) { +func AssertSQL(_ expression1: @autoclosure () -> String, _ expression2: @autoclosure () -> Expressible, file: StaticString = #file, line: UInt = #line) { XCTAssertEqual(expression1(), expression2().asSQL(), file: file, line: line) } -func AssertThrows(@autoclosure _ expression: () throws -> T, file: StaticString = #file, line: UInt = #line) { +func AssertThrows(_ expression: @autoclosure () throws -> T, file: StaticString = #file, line: UInt = #line) { do { - try expression() + _ = try expression() XCTFail("expression expected to throw", file: file, line: line) } catch { XCTAssert(true, file: file, line: line) diff --git a/run-tests.sh b/run-tests.sh new file mode 100755 index 00000000..7a35fb02 --- /dev/null +++ b/run-tests.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -ev +if [ -n "$BUILD_SCHEME" ]; then + make test BUILD_SCHEME="$BUILD_SCHEME" +elif [ -n "$VALIDATOR_SUBSPEC" ]; then + cd CocoaPodsTests && make test +fi