From fbc0ee77bb616198cbfb54b47ab7cb391bd45f99 Mon Sep 17 00:00:00 2001 From: jason Date: Wed, 8 Sep 2021 13:57:24 -0700 Subject: [PATCH 01/11] Change init to fix Swift error --- GRDB/Core/Support/Foundation/DatabaseDateComponents.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift b/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift index a8a634ccf..20dff9652 100644 --- a/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift +++ b/GRDB/Core/Support/Foundation/DatabaseDateComponents.swift @@ -84,8 +84,7 @@ public struct DatabaseDateComponents: DatabaseValueConvertible, StatementColumnC guard let components = optionalComponents else { return nil } - self.dateComponents = components.dateComponents - self.format = components.format + self.init(components.dateComponents, format: components.format) } // MARK: - DatabaseValueConvertible adoption From b0b8872798a717c8b78666a5494df91ba3a2b2b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Mon, 20 Sep 2021 17:14:07 +0200 Subject: [PATCH 02/11] Expose FTS tokenization methods --- GRDB/FTS/FTS3.swift | 36 +++++++++- GRDB/FTS/FTS3Pattern.swift | 6 +- GRDB/FTS/FTS3TokenizerDescriptor.swift | 23 ------ GRDB/FTS/FTS5.swift | 35 +++++++++- GRDB/FTS/FTS5Pattern.swift | 36 ++++------ Tests/GRDBTests/FTS3PatternTests.swift | 92 +++++++++++++++++++++++- Tests/GRDBTests/FTS5PatternTests.swift | 96 ++++++++++++++++++++++++-- 7 files changed, 264 insertions(+), 60 deletions(-) diff --git a/GRDB/FTS/FTS3.swift b/GRDB/FTS/FTS3.swift index 66bdc12cf..3dd31a534 100644 --- a/GRDB/FTS/FTS3.swift +++ b/GRDB/FTS/FTS3.swift @@ -37,7 +37,41 @@ public struct FTS3: VirtualTableModule { /// try db.create(virtualTable: "document", using: FTS3()) { t in /// t.column("content") /// } - public init() { + public init() { } + + /// Returns an array of tokens found in the string argument. + /// + /// For example: + /// + /// FTS3.tokenize("SQLite database") // ["sqlite", "database"] + /// FTS3.tokenize("Gustave Doré") // ["gustave", "doré"]) + /// + /// Results can be altered with an explicit tokenizer - default is `.simple`. + /// See . + /// + /// FTS3.tokenize("SQLite database", withTokenizer: .porter) // ["sqlite", "databas"] + /// FTS3.tokenize("Gustave Doré", withTokenizer: .unicode61()) // ["gustave", "dore"]) + /// + /// Tokenization is performed by the `fts3tokenize` virtual table described + /// at . + public static func tokenize( + _ string: String, + withTokenizer tokenizer: FTS3TokenizerDescriptor = .simple) + -> [String] + { + DatabaseQueue().inDatabase { db in + var tokenizerChunks: [String] = [] + tokenizerChunks.append(tokenizer.name) + for option in tokenizer.arguments { + tokenizerChunks.append("\"\(option)\"") + } + let tokenizerSQL = tokenizerChunks.joined(separator: ", ") + // Assume fts3tokenize virtual table in an in-memory database always succeeds + try! db.execute(sql: "CREATE VIRTUAL TABLE tokens USING fts3tokenize(\(tokenizerSQL))") + return try! String.fetchAll(db, sql: """ + SELECT token FROM tokens WHERE input = ? ORDER BY position + """, arguments: [string]) + } } // MARK: - VirtualTableModule Adoption diff --git a/GRDB/FTS/FTS3Pattern.swift b/GRDB/FTS/FTS3Pattern.swift index f07bf0626..8f01ab5e1 100644 --- a/GRDB/FTS/FTS3Pattern.swift +++ b/GRDB/FTS/FTS3Pattern.swift @@ -41,7 +41,7 @@ public struct FTS3Pattern { /// /// - parameter string: The string to turn into an FTS3 pattern public init?(matchingAnyTokenIn string: String) { - let tokens = FTS3TokenizerDescriptor.simple.tokenize(string) + let tokens = FTS3.tokenize(string, withTokenizer: .simple) guard !tokens.isEmpty else { return nil } try? self.init(rawPattern: tokens.joined(separator: " OR ")) } @@ -54,7 +54,7 @@ public struct FTS3Pattern { /// /// - parameter string: The string to turn into an FTS3 pattern public init?(matchingAllTokensIn string: String) { - let tokens = FTS3TokenizerDescriptor.simple.tokenize(string) + let tokens = FTS3.tokenize(string, withTokenizer: .simple) guard !tokens.isEmpty else { return nil } try? self.init(rawPattern: tokens.joined(separator: " ")) } @@ -67,7 +67,7 @@ public struct FTS3Pattern { /// /// - parameter string: The string to turn into an FTS3 pattern public init?(matchingPhrase string: String) { - let tokens = FTS3TokenizerDescriptor.simple.tokenize(string) + let tokens = FTS3.tokenize(string, withTokenizer: .simple) guard !tokens.isEmpty else { return nil } try? self.init(rawPattern: "\"" + tokens.joined(separator: " ") + "\"") } diff --git a/GRDB/FTS/FTS3TokenizerDescriptor.swift b/GRDB/FTS/FTS3TokenizerDescriptor.swift index 5c2363fee..a1eb0cf62 100644 --- a/GRDB/FTS/FTS3TokenizerDescriptor.swift +++ b/GRDB/FTS/FTS3TokenizerDescriptor.swift @@ -90,27 +90,4 @@ public struct FTS3TokenizerDescriptor { } return FTS3TokenizerDescriptor("unicode61", arguments: arguments) } - - func tokenize(_ string: String) -> [String] { - _tokenize(string) - } - - /// Returns an array of tokens found in the string argument. - /// - /// FTS3TokenizerDescriptor.simple.tokenize("foo bar") // ["foo", "bar"] - private func _tokenize(_ string: String) -> [String] { - DatabaseQueue().inDatabase { db in - var tokenizerChunks: [String] = [] - tokenizerChunks.append(name) - for option in arguments { - tokenizerChunks.append("\"\(option)\"") - } - let tokenizerSQL = tokenizerChunks.joined(separator: ", ") - // Assume fts3tokenize virtual table in an in-memory database always succeeds - try! db.execute(sql: "CREATE VIRTUAL TABLE tokens USING fts3tokenize(\(tokenizerSQL))") - return try! String.fetchAll(db, sql: """ - SELECT token FROM tokens WHERE input = ? ORDER BY position - """, arguments: [string]) - } - } } diff --git a/GRDB/FTS/FTS5.swift b/GRDB/FTS/FTS5.swift index b707c66cf..e9bd7d93e 100644 --- a/GRDB/FTS/FTS5.swift +++ b/GRDB/FTS/FTS5.swift @@ -44,7 +44,40 @@ public struct FTS5: VirtualTableModule { /// } /// /// See - public init() { + public init() { } + + /// Returns an array of tokens found in the string argument. + /// + /// For example: + /// + /// try FTS5.tokenize("SQLite database") // ["sqlite", "database"] + /// try FTS5.tokenize("Gustave Doré") // ["gustave", "doré"]) + /// + /// Results can be altered with an explicit tokenizer - default is `.ascii()`. + /// See . + /// + /// try FTS5.tokenize("SQLite database", withTokenizer: .porter()) // ["sqlite", "databas"] + /// try FTS5.tokenize("Gustave Doré", withTokenizer: .unicode61()) // ["gustave", "dore"]) + /// + /// Synonym (colocated) tokens are not present in the returned array. See + /// `FTS5_TOKEN_COLOCATED` at + /// for more information. + /// + /// - parameter string: The tokenized string. + /// - parameter tokenizer: The tokenizer - defaults to `.ascii()`. + /// - parameter tokenization: The reason why tokenization is requested - + /// defaults to `.query`. + /// - returns: An array of tokens. + /// - throws: An error if tokenization fails. + public static func tokenize( + _ string: String, + withTokenizer tokenizer: FTS5TokenizerDescriptor = .ascii(), + for tokenization: FTS5Tokenization = .query) + throws -> [String] + { + try DatabaseQueue().inDatabase { db in + try db.makeTokenizer(tokenizer).nonSynonymTokens(in: string, for: tokenization) + } } // MARK: - VirtualTableModule Adoption diff --git a/GRDB/FTS/FTS5Pattern.swift b/GRDB/FTS/FTS5Pattern.swift index 6b0a9becd..87689fcd2 100644 --- a/GRDB/FTS/FTS5Pattern.swift +++ b/GRDB/FTS/FTS5Pattern.swift @@ -13,12 +13,9 @@ public struct FTS5Pattern { /// /// - parameter string: The string to turn into an FTS5 pattern public init?(matchingAnyTokenIn string: String) { - guard let tokens = try? DatabaseQueue() - .inDatabase({ try $0.makeTokenizer(.ascii()) .nonSynonymTokens(in: string, for: .query) }) - else { - return nil - } - guard !tokens.isEmpty else { return nil } + guard let tokens = try? FTS5.tokenize(string, withTokenizer: .ascii(), for: .query), + !tokens.isEmpty + else { return nil } try? self.init(rawPattern: tokens.joined(separator: " OR ")) } @@ -30,12 +27,9 @@ public struct FTS5Pattern { /// /// - parameter string: The string to turn into an FTS5 pattern public init?(matchingAllTokensIn string: String) { - guard let tokens = try? DatabaseQueue() - .inDatabase({ try $0.makeTokenizer(.ascii()).nonSynonymTokens(in: string, for: .query) }) - else { - return nil - } - guard !tokens.isEmpty else { return nil } + guard let tokens = try? FTS5.tokenize(string, withTokenizer: .ascii(), for: .query), + !tokens.isEmpty + else { return nil } try? self.init(rawPattern: tokens.joined(separator: " ")) } @@ -47,12 +41,9 @@ public struct FTS5Pattern { /// /// - parameter string: The string to turn into an FTS5 pattern public init?(matchingPhrase string: String) { - guard let tokens = try? DatabaseQueue() - .inDatabase({ try $0.makeTokenizer(.ascii()) .nonSynonymTokens(in: string, for: .query) }) - else { - return nil - } - guard !tokens.isEmpty else { return nil } + guard let tokens = try? FTS5.tokenize(string, withTokenizer: .ascii(), for: .query), + !tokens.isEmpty + else { return nil } try? self.init(rawPattern: "\"" + tokens.joined(separator: " ") + "\"") } @@ -67,12 +58,9 @@ public struct FTS5Pattern { /// /// - parameter string: The string to turn into an FTS5 pattern public init?(matchingPrefixPhrase string: String) { - guard let tokens = try? DatabaseQueue() - .inDatabase({ try $0.makeTokenizer(.ascii()) .nonSynonymTokens(in: string, for: .query) }) - else { - return nil - } - guard !tokens.isEmpty else { return nil } + guard let tokens = try? FTS5.tokenize(string, withTokenizer: .ascii(), for: .query), + !tokens.isEmpty + else { return nil } try? self.init(rawPattern: "^\"" + tokens.joined(separator: " ") + "\"") } diff --git a/Tests/GRDBTests/FTS3PatternTests.swift b/Tests/GRDBTests/FTS3PatternTests.swift index 1923a0b39..e918b5d0b 100644 --- a/Tests/GRDBTests/FTS3PatternTests.swift +++ b/Tests/GRDBTests/FTS3PatternTests.swift @@ -51,7 +51,7 @@ class FTS3PatternTests: GRDBTestCase { } } } - + func testInvalidFTS3Pattern() { let invalidRawPatterns = ["NOT", "(", "AND", "OR", "\""] for rawPattern in invalidRawPatterns { @@ -65,6 +65,92 @@ class FTS3PatternTests: GRDBTestCase { } } + func testFTS3Tokenize() { + // Empty query + XCTAssertEqual(FTS3.tokenize(""), []) + XCTAssertEqual(FTS3.tokenize("", withTokenizer: .simple), []) + XCTAssertEqual(FTS3.tokenize("", withTokenizer: .porter), []) + XCTAssertEqual(FTS3.tokenize("", withTokenizer: .unicode61()), []) + XCTAssertEqual(FTS3.tokenize("", withTokenizer: .unicode61(diacritics: .keep)), []) + + XCTAssertEqual(FTS3.tokenize("?!"), []) + XCTAssertEqual(FTS3.tokenize("?!", withTokenizer: .simple), []) + XCTAssertEqual(FTS3.tokenize("?!", withTokenizer: .porter), []) + XCTAssertEqual(FTS3.tokenize("?!", withTokenizer: .unicode61()), []) + XCTAssertEqual(FTS3.tokenize("?!", withTokenizer: .unicode61(diacritics: .keep)), []) + + // Token queries + XCTAssertEqual(FTS3.tokenize("Moby"), ["moby"]) + XCTAssertEqual(FTS3.tokenize("Moby", withTokenizer: .simple), ["moby"]) + XCTAssertEqual(FTS3.tokenize("Moby", withTokenizer: .porter), ["mobi"]) + XCTAssertEqual(FTS3.tokenize("Moby", withTokenizer: .unicode61()), ["moby"]) + XCTAssertEqual(FTS3.tokenize("Moby", withTokenizer: .unicode61(diacritics: .keep)), ["moby"]) + + XCTAssertEqual(FTS3.tokenize("écarlates"), ["écarlates"]) + XCTAssertEqual(FTS3.tokenize("écarlates", withTokenizer: .simple), ["écarlates"]) + XCTAssertEqual(FTS3.tokenize("écarlates", withTokenizer: .porter), ["écarlates"]) + XCTAssertEqual(FTS3.tokenize("écarlates", withTokenizer: .unicode61()), ["ecarlates"]) + XCTAssertEqual(FTS3.tokenize("écarlates", withTokenizer: .unicode61(diacritics: .keep)), ["écarlates"]) + + XCTAssertEqual(FTS3.tokenize("fooéı👨👨🏿🇫🇷🇨🇮"), ["fooéı👨👨🏿🇫🇷🇨🇮"]) + XCTAssertEqual(FTS3.tokenize("fooéı👨👨🏿🇫🇷🇨🇮", withTokenizer: .simple), ["fooéı👨👨🏿🇫🇷🇨🇮"]) + XCTAssertEqual(FTS3.tokenize("fooéı👨👨🏿🇫🇷🇨🇮", withTokenizer: .porter), ["fooéı👇�🇨🇮"]) // ¯\_(ツ)_/¯ + XCTAssertEqual(FTS3.tokenize("fooéı👨👨🏿🇫🇷🇨🇮", withTokenizer: .unicode61()), ["fooeı", "🏿"]) // ¯\_(ツ)_/¯ + XCTAssertEqual(FTS3.tokenize("fooéı👨👨🏿🇫🇷🇨🇮", withTokenizer: .unicode61(diacritics: .keep)), ["fooéı", "🏿"]) // ¯\_(ツ)_/¯ + + XCTAssertEqual(FTS3.tokenize("SQLite database"), ["sqlite", "database"]) + XCTAssertEqual(FTS3.tokenize("SQLite database", withTokenizer: .simple), ["sqlite", "database"]) + XCTAssertEqual(FTS3.tokenize("SQLite database", withTokenizer: .porter), ["sqlite", "databas"]) + XCTAssertEqual(FTS3.tokenize("SQLite database", withTokenizer: .unicode61()), ["sqlite", "database"]) + XCTAssertEqual(FTS3.tokenize("SQLite database", withTokenizer: .unicode61(diacritics: .keep)), ["sqlite", "database"]) + + XCTAssertEqual(FTS3.tokenize("Édouard Manet"), ["Édouard", "manet"]) + XCTAssertEqual(FTS3.tokenize("Édouard Manet", withTokenizer: .simple), ["Édouard", "manet"]) + XCTAssertEqual(FTS3.tokenize("Édouard Manet", withTokenizer: .porter), ["Édouard", "manet"]) + XCTAssertEqual(FTS3.tokenize("Édouard Manet", withTokenizer: .unicode61()), ["edouard", "manet"]) + XCTAssertEqual(FTS3.tokenize("Édouard Manet", withTokenizer: .unicode61(diacritics: .keep)), ["édouard", "manet"]) + + // Prefix queries + XCTAssertEqual(FTS3.tokenize("*"), []) + XCTAssertEqual(FTS3.tokenize("*", withTokenizer: .simple), []) + XCTAssertEqual(FTS3.tokenize("*", withTokenizer: .porter), []) + XCTAssertEqual(FTS3.tokenize("*", withTokenizer: .unicode61()), []) + XCTAssertEqual(FTS3.tokenize("*", withTokenizer: .unicode61(diacritics: .keep)), []) + + XCTAssertEqual(FTS3.tokenize("Robin*"), ["robin"]) + XCTAssertEqual(FTS3.tokenize("Robin*", withTokenizer: .simple), ["robin"]) + XCTAssertEqual(FTS3.tokenize("Robin*", withTokenizer: .porter), ["robin"]) + XCTAssertEqual(FTS3.tokenize("Robin*", withTokenizer: .unicode61()), ["robin"]) + XCTAssertEqual(FTS3.tokenize("Robin*", withTokenizer: .unicode61(diacritics: .keep)), ["robin"]) + + // Phrase queries + XCTAssertEqual(FTS3.tokenize("\"foulent muscles\""), ["foulent", "muscles"]) + XCTAssertEqual(FTS3.tokenize("\"foulent muscles\"", withTokenizer: .simple), ["foulent", "muscles"]) + XCTAssertEqual(FTS3.tokenize("\"foulent muscles\"", withTokenizer: .porter), ["foulent", "muscl"]) + XCTAssertEqual(FTS3.tokenize("\"foulent muscles\"", withTokenizer: .unicode61()), ["foulent", "muscles"]) + XCTAssertEqual(FTS3.tokenize("\"foulent muscles\"", withTokenizer: .unicode61(diacritics: .keep)), ["foulent", "muscles"]) + + XCTAssertEqual(FTS3.tokenize("\"Kim Stan* Robin*\""), ["kim", "stan", "robin"]) + XCTAssertEqual(FTS3.tokenize("\"Kim Stan* Robin*\"", withTokenizer: .simple), ["kim", "stan", "robin"]) + XCTAssertEqual(FTS3.tokenize("\"Kim Stan* Robin*\"", withTokenizer: .porter), ["kim", "stan", "robin"]) + XCTAssertEqual(FTS3.tokenize("\"Kim Stan* Robin*\"", withTokenizer: .unicode61()), ["kim", "stan", "robin"]) + XCTAssertEqual(FTS3.tokenize("\"Kim Stan* Robin*\"", withTokenizer: .unicode61(diacritics: .keep)), ["kim", "stan", "robin"]) + + // Logical queries + XCTAssertEqual(FTS3.tokenize("years AND months"), ["years", "and", "months"]) + XCTAssertEqual(FTS3.tokenize("years AND months", withTokenizer: .simple), ["years", "and", "months"]) + XCTAssertEqual(FTS3.tokenize("years AND months", withTokenizer: .porter), ["year", "and", "month"]) + XCTAssertEqual(FTS3.tokenize("years AND months", withTokenizer: .unicode61()), ["years", "and", "months"]) + XCTAssertEqual(FTS3.tokenize("years AND months", withTokenizer: .unicode61(diacritics: .keep)), ["years", "and", "months"]) + + // column queries + XCTAssertEqual(FTS3.tokenize("title:brest"), ["title", "brest"]) + XCTAssertEqual(FTS3.tokenize("title:brest", withTokenizer: .simple), ["title", "brest"]) + XCTAssertEqual(FTS3.tokenize("title:brest", withTokenizer: .porter), ["titl", "brest"]) + XCTAssertEqual(FTS3.tokenize("title:brest", withTokenizer: .unicode61()), ["title", "brest"]) + XCTAssertEqual(FTS3.tokenize("title:brest", withTokenizer: .unicode61(diacritics: .keep)), ["title", "brest"]) + } + func testFTS3PatternWithAnyToken() throws { let wrongInputs = ["", "*", "^", " ", "(", "()", "\"", "?!"] for string in wrongInputs { @@ -113,7 +199,7 @@ class FTS3PatternTests: GRDBTestCase { (" \t\nyears \t\nmonths \t\n", "years months", 1), ("\"years months days\"", "years months days", 1), ("FOOÉı👨👨🏿🇫🇷🇨🇮", "fooÉı👨👨🏿🇫🇷🇨🇮", 0), - ] + ] for (string, expectedRawPattern, expectedCount) in cases { if let pattern = FTS3Pattern(matchingAllTokensIn: string) { let rawPattern = String.fromDatabaseValue(pattern.databaseValue)! @@ -143,7 +229,7 @@ class FTS3PatternTests: GRDBTestCase { (" \t\nyears \t\nmonths \t\n", "\"years months\"", 0), ("\"years months days\"", "\"years months days\"", 0), ("FOOÉı👨👨🏿🇫🇷🇨🇮", "\"fooÉı👨👨🏿🇫🇷🇨🇮\"", 0), - ] + ] for (string, expectedRawPattern, expectedCount) in cases { if let pattern = FTS3Pattern(matchingPhrase: string) { let rawPattern = String.fromDatabaseValue(pattern.databaseValue)! diff --git a/Tests/GRDBTests/FTS5PatternTests.swift b/Tests/GRDBTests/FTS5PatternTests.swift index a07e3638a..d07ca0469 100644 --- a/Tests/GRDBTests/FTS5PatternTests.swift +++ b/Tests/GRDBTests/FTS5PatternTests.swift @@ -49,7 +49,93 @@ class FTS5PatternTests: GRDBTestCase { } } } - + + func testFTS5Tokenize() throws { + // Empty query + try XCTAssertEqual(FTS5.tokenize(""), []) + try XCTAssertEqual(FTS5.tokenize("", withTokenizer: .ascii()), []) + try XCTAssertEqual(FTS5.tokenize("", withTokenizer: .porter()), []) + try XCTAssertEqual(FTS5.tokenize("", withTokenizer: .unicode61()), []) + try XCTAssertEqual(FTS5.tokenize("", withTokenizer: .unicode61(diacritics: .keep)), []) + + try XCTAssertEqual(FTS5.tokenize("?!"), []) + try XCTAssertEqual(FTS5.tokenize("?!", withTokenizer: .ascii()), []) + try XCTAssertEqual(FTS5.tokenize("?!", withTokenizer: .porter()), []) + try XCTAssertEqual(FTS5.tokenize("?!", withTokenizer: .unicode61()), []) + try XCTAssertEqual(FTS5.tokenize("?!", withTokenizer: .unicode61(diacritics: .keep)), []) + + // Token queries + try XCTAssertEqual(FTS5.tokenize("Moby"), ["moby"]) + try XCTAssertEqual(FTS5.tokenize("Moby", withTokenizer: .ascii()), ["moby"]) + try XCTAssertEqual(FTS5.tokenize("Moby", withTokenizer: .porter()), ["mobi"]) + try XCTAssertEqual(FTS5.tokenize("Moby", withTokenizer: .unicode61()), ["moby"]) + try XCTAssertEqual(FTS5.tokenize("Moby", withTokenizer: .unicode61(diacritics: .keep)), ["moby"]) + + try XCTAssertEqual(FTS5.tokenize("écarlates"), ["écarlates"]) + try XCTAssertEqual(FTS5.tokenize("écarlates", withTokenizer: .ascii()), ["écarlates"]) + try XCTAssertEqual(FTS5.tokenize("écarlates", withTokenizer: .porter()), ["ecarl"]) + try XCTAssertEqual(FTS5.tokenize("écarlates", withTokenizer: .unicode61()), ["ecarlates"]) + try XCTAssertEqual(FTS5.tokenize("écarlates", withTokenizer: .unicode61(diacritics: .keep)), ["écarlates"]) + + try XCTAssertEqual(FTS5.tokenize("fooéı👨👨🏿🇫🇷🇨🇮"), ["fooéı👨👨🏿🇫🇷🇨🇮"]) + try XCTAssertEqual(FTS5.tokenize("fooéı👨👨🏿🇫🇷🇨🇮", withTokenizer: .ascii()), ["fooéı👨👨🏿🇫🇷🇨🇮"]) + try XCTAssertEqual(FTS5.tokenize("fooéı👨👨🏿🇫🇷🇨🇮", withTokenizer: .porter()), ["fooeı", "🏿"]) // ¯\_(ツ)_/¯ + try XCTAssertEqual(FTS5.tokenize("fooéı👨👨🏿🇫🇷🇨🇮", withTokenizer: .unicode61()), ["fooeı", "🏿"]) // ¯\_(ツ)_/¯ + try XCTAssertEqual(FTS5.tokenize("fooéı👨👨🏿🇫🇷🇨🇮", withTokenizer: .unicode61(diacritics: .keep)), ["fooéı", "🏿"]) // ¯\_(ツ)_/¯ + + try XCTAssertEqual(FTS5.tokenize("SQLite database"), ["sqlite", "database"]) + try XCTAssertEqual(FTS5.tokenize("SQLite database", withTokenizer: .ascii()), ["sqlite", "database"]) + try XCTAssertEqual(FTS5.tokenize("SQLite database", withTokenizer: .porter()), ["sqlite", "databas"]) + try XCTAssertEqual(FTS5.tokenize("SQLite database", withTokenizer: .unicode61()), ["sqlite", "database"]) + try XCTAssertEqual(FTS5.tokenize("SQLite database", withTokenizer: .unicode61(diacritics: .keep)), ["sqlite", "database"]) + + try XCTAssertEqual(FTS5.tokenize("Édouard Manet"), ["Édouard", "manet"]) + try XCTAssertEqual(FTS5.tokenize("Édouard Manet", withTokenizer: .ascii()), ["Édouard", "manet"]) + try XCTAssertEqual(FTS5.tokenize("Édouard Manet", withTokenizer: .porter()), ["edouard", "manet"]) + try XCTAssertEqual(FTS5.tokenize("Édouard Manet", withTokenizer: .unicode61()), ["edouard", "manet"]) + try XCTAssertEqual(FTS5.tokenize("Édouard Manet", withTokenizer: .unicode61(diacritics: .keep)), ["édouard", "manet"]) + + // Prefix queries + try XCTAssertEqual(FTS5.tokenize("*"), []) + try XCTAssertEqual(FTS5.tokenize("*", withTokenizer: .ascii()), []) + try XCTAssertEqual(FTS5.tokenize("*", withTokenizer: .porter()), []) + try XCTAssertEqual(FTS5.tokenize("*", withTokenizer: .unicode61()), []) + try XCTAssertEqual(FTS5.tokenize("*", withTokenizer: .unicode61(diacritics: .keep)), []) + + try XCTAssertEqual(FTS5.tokenize("Robin*"), ["robin"]) + try XCTAssertEqual(FTS5.tokenize("Robin*", withTokenizer: .ascii()), ["robin"]) + try XCTAssertEqual(FTS5.tokenize("Robin*", withTokenizer: .porter()), ["robin"]) + try XCTAssertEqual(FTS5.tokenize("Robin*", withTokenizer: .unicode61()), ["robin"]) + try XCTAssertEqual(FTS5.tokenize("Robin*", withTokenizer: .unicode61(diacritics: .keep)), ["robin"]) + + // Phrase queries + try XCTAssertEqual(FTS5.tokenize("\"foulent muscles\""), ["foulent", "muscles"]) + try XCTAssertEqual(FTS5.tokenize("\"foulent muscles\"", withTokenizer: .ascii()), ["foulent", "muscles"]) + try XCTAssertEqual(FTS5.tokenize("\"foulent muscles\"", withTokenizer: .porter()), ["foulent", "muscl"]) + try XCTAssertEqual(FTS5.tokenize("\"foulent muscles\"", withTokenizer: .unicode61()), ["foulent", "muscles"]) + try XCTAssertEqual(FTS5.tokenize("\"foulent muscles\"", withTokenizer: .unicode61(diacritics: .keep)), ["foulent", "muscles"]) + + try XCTAssertEqual(FTS5.tokenize("\"Kim Stan* Robin*\""), ["kim", "stan", "robin"]) + try XCTAssertEqual(FTS5.tokenize("\"Kim Stan* Robin*\"", withTokenizer: .ascii()), ["kim", "stan", "robin"]) + try XCTAssertEqual(FTS5.tokenize("\"Kim Stan* Robin*\"", withTokenizer: .porter()), ["kim", "stan", "robin"]) + try XCTAssertEqual(FTS5.tokenize("\"Kim Stan* Robin*\"", withTokenizer: .unicode61()), ["kim", "stan", "robin"]) + try XCTAssertEqual(FTS5.tokenize("\"Kim Stan* Robin*\"", withTokenizer: .unicode61(diacritics: .keep)), ["kim", "stan", "robin"]) + + // Logical queries + try XCTAssertEqual(FTS5.tokenize("years AND months"), ["years", "and", "months"]) + try XCTAssertEqual(FTS5.tokenize("years AND months", withTokenizer: .ascii()), ["years", "and", "months"]) + try XCTAssertEqual(FTS5.tokenize("years AND months", withTokenizer: .porter()), ["year", "and", "month"]) + try XCTAssertEqual(FTS5.tokenize("years AND months", withTokenizer: .unicode61()), ["years", "and", "months"]) + try XCTAssertEqual(FTS5.tokenize("years AND months", withTokenizer: .unicode61(diacritics: .keep)), ["years", "and", "months"]) + + // column queries + try XCTAssertEqual(FTS5.tokenize("title:brest"), ["title", "brest"]) + try XCTAssertEqual(FTS5.tokenize("title:brest", withTokenizer: .ascii()), ["title", "brest"]) + try XCTAssertEqual(FTS5.tokenize("title:brest", withTokenizer: .porter()), ["titl", "brest"]) + try XCTAssertEqual(FTS5.tokenize("title:brest", withTokenizer: .unicode61()), ["title", "brest"]) + try XCTAssertEqual(FTS5.tokenize("title:brest", withTokenizer: .unicode61(diacritics: .keep)), ["title", "brest"]) + } + func testInvalidFTS5Pattern() throws { let dbQueue = try makeDatabaseQueue() dbQueue.inDatabase { db in @@ -65,7 +151,7 @@ class FTS5PatternTests: GRDBTestCase { } } } - + func testFTS5PatternWithAnyToken() throws { let wrongInputs = ["", "*", "^", " ", "(", "()", "\"", "?!"] for string in wrongInputs { @@ -114,7 +200,7 @@ class FTS5PatternTests: GRDBTestCase { (" \t\nyears \t\nmonths \t\n", "years months", 1), ("\"years months days\"", "years months days", 1), ("FOOÉı👨👨🏿🇫🇷🇨🇮", "fooÉı👨👨🏿🇫🇷🇨🇮", 0), - ] + ] for (string, expectedRawPattern, expectedCount) in cases { if let pattern = FTS5Pattern(matchingAllTokensIn: string) { let rawPattern = String.fromDatabaseValue(pattern.databaseValue)! @@ -144,7 +230,7 @@ class FTS5PatternTests: GRDBTestCase { (" \t\nyears \t\nmonths \t\n", "\"years months\"", 0), ("\"years months days\"", "\"years months days\"", 0), ("FOOÉı👨👨🏿🇫🇷🇨🇮", "\"fooÉı👨👨🏿🇫🇷🇨🇮\"", 0), - ] + ] for (string, expectedRawPattern, expectedCount) in cases { if let pattern = FTS5Pattern(matchingPhrase: string) { let rawPattern = String.fromDatabaseValue(pattern.databaseValue)! @@ -176,7 +262,7 @@ class FTS5PatternTests: GRDBTestCase { (" \t\nyears \t\nmonths \t\n", "^\"years months\"", 0), ("\"years months days\"", "^\"years months days\"", 0), ("FOOÉı👨👨🏿🇫🇷🇨🇮", "^\"fooÉı👨👨🏿🇫🇷🇨🇮\"", 0), - ] + ] for (string, expectedRawPattern, expectedCount) in cases { if let pattern = FTS5Pattern(matchingPrefixPhrase: string) { let rawPattern = String.fromDatabaseValue(pattern.databaseValue)! From dfe519ea9b00fa65e33c7562761eb27aed88f465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Mon, 20 Sep 2021 17:35:47 +0200 Subject: [PATCH 03/11] Build FTS patterns from prefixes --- GRDB/FTS/FTS3Pattern.swift | 13 +++++++++++ GRDB/FTS/FTS5Pattern.swift | 14 ++++++++++++ Tests/GRDBTests/FTS3PatternTests.swift | 30 ++++++++++++++++++++++++++ Tests/GRDBTests/FTS5PatternTests.swift | 30 ++++++++++++++++++++++++++ 4 files changed, 87 insertions(+) diff --git a/GRDB/FTS/FTS3Pattern.swift b/GRDB/FTS/FTS3Pattern.swift index 8f01ab5e1..8b4e7e5b0 100644 --- a/GRDB/FTS/FTS3Pattern.swift +++ b/GRDB/FTS/FTS3Pattern.swift @@ -59,6 +59,19 @@ public struct FTS3Pattern { try? self.init(rawPattern: tokens.joined(separator: " ")) } + /// Creates a pattern that matches all token prefixes found in the input + /// string; returns nil if no pattern could be built. + /// + /// FTS3Pattern(matchingAllTokensIn: "") // nil + /// FTS3Pattern(matchingAllTokensIn: "foo bar") // foo* bar* + /// + /// - parameter string: The string to turn into an FTS3 pattern + public init?(matchingAllPrefixesIn string: String) { + let tokens = FTS3.tokenize(string, withTokenizer: .simple) + guard !tokens.isEmpty else { return nil } + try? self.init(rawPattern: tokens.map { "\($0)*" }.joined(separator: " ")) + } + /// Creates a pattern that matches a contiguous string; returns nil if no /// pattern could be built. /// diff --git a/GRDB/FTS/FTS5Pattern.swift b/GRDB/FTS/FTS5Pattern.swift index 87689fcd2..d746895c7 100644 --- a/GRDB/FTS/FTS5Pattern.swift +++ b/GRDB/FTS/FTS5Pattern.swift @@ -33,6 +33,20 @@ public struct FTS5Pattern { try? self.init(rawPattern: tokens.joined(separator: " ")) } + /// Creates a pattern that matches all token prefixes found in the input + /// string; returns nil if no pattern could be built. + /// + /// FTS3Pattern(matchingAllTokensIn: "") // nil + /// FTS3Pattern(matchingAllTokensIn: "foo bar") // foo* bar* + /// + /// - parameter string: The string to turn into an FTS3 pattern + public init?(matchingAllPrefixesIn string: String) { + guard let tokens = try? FTS5.tokenize(string, withTokenizer: .ascii(), for: .query), + !tokens.isEmpty + else { return nil } + try? self.init(rawPattern: tokens.map { "\($0)*" }.joined(separator: " ")) + } + /// Creates a pattern that matches a contiguous string; returns nil if no /// pattern could be built. /// diff --git a/Tests/GRDBTests/FTS3PatternTests.swift b/Tests/GRDBTests/FTS3PatternTests.swift index e918b5d0b..27ade619e 100644 --- a/Tests/GRDBTests/FTS3PatternTests.swift +++ b/Tests/GRDBTests/FTS3PatternTests.swift @@ -211,6 +211,36 @@ class FTS3PatternTests: GRDBTestCase { } } + func testFTS3PatternWithAllPrefixes() throws { + let wrongInputs = ["", "*", "^", " ", "(", "()", "\"", "?!"] + for string in wrongInputs { + if let pattern = FTS3Pattern(matchingAllPrefixesIn: string) { + let rawPattern = String.fromDatabaseValue(pattern.databaseValue)! + XCTFail("Unexpected raw pattern \(String(reflecting: rawPattern)) from string \(String(reflecting: string))") + } + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + // Couples (pattern, expected raw pattern, expected count of matching rows) + let cases = [ + ("écarlate", "écarlate*", 1), + ("^Mob*", "mob*", 1), + (" \t\nyear \t\nmonth \t\n", "year* month*", 1), + ("\"year month day\"", "year* month* day*", 1), + ("FOOÉı👨👨🏿🇫🇷", "fooÉı👨👨🏿🇫🇷*", 0), + ] + for (string, expectedRawPattern, expectedCount) in cases { + if let pattern = FTS3Pattern(matchingAllPrefixesIn: string) { + let rawPattern = String.fromDatabaseValue(pattern.databaseValue)! + XCTAssertEqual(rawPattern, expectedRawPattern) + let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])! + XCTAssertEqual(count, expectedCount, "Expected pattern \(String(reflecting: rawPattern)) to yield \(expectedCount) results") + } + } + } + } + func testFTS3PatternWithPhrase() throws { let wrongInputs = ["", "*", "^", " ", "(", "()", "\"", "?!"] for string in wrongInputs { diff --git a/Tests/GRDBTests/FTS5PatternTests.swift b/Tests/GRDBTests/FTS5PatternTests.swift index d07ca0469..42b101f32 100644 --- a/Tests/GRDBTests/FTS5PatternTests.swift +++ b/Tests/GRDBTests/FTS5PatternTests.swift @@ -212,6 +212,36 @@ class FTS5PatternTests: GRDBTestCase { } } + func testFTS5PatternWithAllPrefixes() throws { + let wrongInputs = ["", "*", "^", " ", "(", "()", "\"", "?!"] + for string in wrongInputs { + if let pattern = FTS5Pattern(matchingAllPrefixesIn: string) { + let rawPattern = String.fromDatabaseValue(pattern.databaseValue)! + XCTFail("Unexpected raw pattern \(String(reflecting: rawPattern)) from string \(String(reflecting: string))") + } + } + + let dbQueue = try makeDatabaseQueue() + try dbQueue.inDatabase { db in + // Couples (pattern, expected raw pattern, expected count of matching rows) + let cases = [ + ("écarlate", "écarlate*", 1), + ("^Mob*", "mob*", 1), + (" \t\nyear \t\nmonth \t\n", "year* month*", 1), + ("\"year month day\"", "year* month* day*", 1), + ("FOOÉı👨👨🏿🇫🇷", "fooÉı👨👨🏿🇫🇷*", 0), + ] + for (string, expectedRawPattern, expectedCount) in cases { + if let pattern = FTS5Pattern(matchingAllPrefixesIn: string) { + let rawPattern = String.fromDatabaseValue(pattern.databaseValue)! + XCTAssertEqual(rawPattern, expectedRawPattern) + let count = try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM books WHERE books MATCH ?", arguments: [pattern])! + XCTAssertEqual(count, expectedCount, "Expected pattern \(String(reflecting: rawPattern)) to yield \(expectedCount) results") + } + } + } + } + func testFTS5PatternWithPhrase() throws { let wrongInputs = ["", "*", "^", " ", "(", "()", "\"", "?!"] for string in wrongInputs { From 46eceb5e28de9914051a18b46c096f366fb2e78e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Mon, 20 Sep 2021 17:47:17 +0200 Subject: [PATCH 04/11] Document prefix-based FTS patterns --- Documentation/FullTextSearch.md | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/Documentation/FullTextSearch.md b/Documentation/FullTextSearch.md index f47fa96cd..a0356fa47 100644 --- a/Documentation/FullTextSearch.md +++ b/Documentation/FullTextSearch.md @@ -248,6 +248,7 @@ struct FTS3Pattern { init(rawPattern: String) throws init?(matchingAnyTokenIn string: String) init?(matchingAllTokensIn string: String) + init?(matchingAllPrefixesIn string: String) init?(matchingPhrase string: String) } ``` @@ -257,18 +258,25 @@ The first initializer validates your raw patterns against the query grammar, and ```swift // OK: FTS3Pattern let pattern = try FTS3Pattern(rawPattern: "sqlite AND database") + // DatabaseError: malformed MATCH expression: [AND] let pattern = try FTS3Pattern(rawPattern: "AND") ``` -The three other initializers don't throw. They build a valid pattern from any string, **including strings provided by users of your application**. They let you find documents that match all given words, any given word, or a full phrase, depending on the needs of your application: +The other initializers don't throw. They build a valid pattern from any string, **including strings provided by users of your application**. They let you find documents that match any given word, all given words or prefixes, or a full phrase, depending on the needs of your application: ```swift let query = "SQLite database" + // Matches documents that contain "SQLite" or "database" let pattern = FTS3Pattern(matchingAnyTokenIn: query) -// Matches documents that contain both "SQLite" and "database" + +// Matches documents that contain "SQLite" and "database" let pattern = FTS3Pattern(matchingAllTokensIn: query) + +// Matches documents that contain words that start with "SQLite" and words that start with "database" +let pattern = FTS3Pattern(matchingAllPrefixesIn: query) + // Matches documents that contain "SQLite database" let pattern = FTS3Pattern(matchingPhrase: query) ``` @@ -493,7 +501,9 @@ extension Database { struct FTS5Pattern { init?(matchingAnyTokenIn string: String) init?(matchingAllTokensIn string: String) + init?(matchingAllPrefixesIn string: String) init?(matchingPhrase string: String) + init?(matchingPrefixPhrase string: String) } ``` @@ -502,8 +512,10 @@ The `Database.makeFTS5Pattern(rawPattern:forTable:)` method validates your raw p ```swift // OK: FTS5Pattern try db.makeFTS5Pattern(rawPattern: "sqlite", forTable: "book") + // DatabaseError: syntax error near \"AND\" try db.makeFTS5Pattern(rawPattern: "AND", forTable: "book") + // DatabaseError: no such column: missing try db.makeFTS5Pattern(rawPattern: "missing: sqlite", forTable: "book") ``` @@ -512,12 +524,19 @@ The FTS5Pattern initializers don't throw. They build a valid pattern from any st ```swift let query = "SQLite database" + // Matches documents that contain "SQLite" or "database" let pattern = FTS5Pattern(matchingAnyTokenIn: query) -// Matches documents that contain both "SQLite" and "database" + +// Matches documents that contain "SQLite" and "database" let pattern = FTS5Pattern(matchingAllTokensIn: query) + +// Matches documents that contain words that start with "SQLite" and words that start with "database" +let pattern = FTS5Pattern(matchingAllPrefixesIn: query) + // Matches documents that contain "SQLite database" let pattern = FTS5Pattern(matchingPhrase: query) + // Matches documents that start with "SQLite database" let pattern = FTS5Pattern(matchingPrefixPhrase: query) ``` From 7ae50103535c63ef478db3f39d06446a6e375ab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Mon, 20 Sep 2021 17:53:59 +0200 Subject: [PATCH 05/11] Document the tokenize(_:) method --- Documentation/FullTextSearch.md | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/Documentation/FullTextSearch.md b/Documentation/FullTextSearch.md index a0356fa47..4d36f9999 100644 --- a/Documentation/FullTextSearch.md +++ b/Documentation/FullTextSearch.md @@ -226,6 +226,18 @@ See below some examples of matches: It does not provide stemming, and won't match "databases" with "database". +You can tokenize strings when needed: + +```swift +// Default tokenization using the `simple` tokenizer: +FTS3.tokenize("SQLite database") // ["sqlite", "database"] +FTS3.tokenize("Gustave Doré") // ["gustave", "doré"]) + +// Tokenization with an explicit tokenizer: +FTS3.tokenize("SQLite database", withTokenizer: .porter) // ["sqlite", "databas"] +FTS3.tokenize("Gustave Doré", withTokenizer: .unicode61()) // ["gustave", "dore"]) +``` + See [SQLite tokenizers](https://www.sqlite.org/fts3.html#tokenizer) for more information. @@ -452,7 +464,7 @@ See below some examples of matches: ```swift try db.create(virtualTable: "book", using: FTS5()) { t in - t.tokenizer = .ascii + t.tokenizer = .ascii() } ``` @@ -466,8 +478,8 @@ See below some examples of matches: ```swift try db.create(virtualTable: "book", using: FTS5()) { t in - t.tokenizer = .porter() // porter wrapping unicode61 (the default) - t.tokenizer = .porter(.ascii) // porter wrapping ascii + t.tokenizer = .porter() // porter wrapping unicode61 (the default) + t.tokenizer = .porter(.ascii()) // porter wrapping ascii t.tokenizer = .porter(.unicode61(diacritics: .keep)) // porter wrapping unicode61 without diacritics stripping } ``` @@ -476,6 +488,18 @@ See below some examples of matches: It strips diacritics from latin script characters if it wraps unicode61, and does not if it wraps ascii (see the example above). +You can tokenize strings when needed: + +```swift +// Default tokenization using the `ascii` tokenizer: +try FTS5.tokenize("SQLite database") // ["sqlite", "database"] +try FTS5.tokenize("Gustave Doré") // ["gustave", "doré"]) + +// Tokenization with an explicit tokenizer: +try FTS5.tokenize("SQLite database", withTokenizer: .porter()) // ["sqlite", "databas"] +try FTS5.tokenize("Gustave Doré", withTokenizer: .unicode61()) // ["gustave", "dore"]) +``` + See [SQLite tokenizers](https://www.sqlite.org/fts5.html#tokenizers) for more information, and [custom FTS5 tokenizers](FTS5Tokenizers.md) in order to add your own tokenizers. From bcd65f534b43346097c261b981059007057b9d84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Mon, 20 Sep 2021 17:55:56 +0200 Subject: [PATCH 06/11] CHANGELOG --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2225b1b5..1fe2c2507 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,6 +78,11 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: --- +## Unreleased + +- **New**: `FTS3Pattern(matchingAllPrefixesIn:)` and `FTS5Pattern(matchingAllPrefixesIn:)` let you build full-text search patterns suitable for prefix queries. +- **New**: `FTS3.tokenize(_:)` and `FTS5.tokenize(_:)` let you tokenize input strings. + ## 5.11.0 Released September 3, 2021 • [diff](https://github.com/groue/GRDB.swift/compare/v5.10.0...v5.11.0) From c0d70f9ef0569b34220ef77b7e003c8f18fc17eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Tue, 21 Sep 2021 19:22:01 +0200 Subject: [PATCH 07/11] Refactor FTS5 tokenization in order to support custom tokenizers --- CHANGELOG.md | 3 +- Documentation/FullTextSearch.md | 33 +++++-- GRDB/FTS/FTS5.swift | 29 +++---- GRDB/FTS/FTS5Pattern.swift | 30 +++---- GRDB/FTS/FTS5Tokenizer.swift | 50 ++++++++--- GRDB/FTS/FTS5WrapperTokenizer.swift | 2 +- Tests/GRDBTests/FTS3PatternTests.swift | 86 ------------------- Tests/GRDBTests/FTS3TokenizerTests.swift | 86 +++++++++++++++++++ .../GRDBTests/FTS5CustomTokenizerTests.swift | 45 ++++++++-- Tests/GRDBTests/FTS5PatternTests.swift | 86 ------------------- Tests/GRDBTests/FTS5TokenizerTests.swift | 80 +++++++++++++++++ 11 files changed, 292 insertions(+), 238 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fe2c2507..5dbab1fa3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,7 +81,8 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: ## Unreleased - **New**: `FTS3Pattern(matchingAllPrefixesIn:)` and `FTS5Pattern(matchingAllPrefixesIn:)` let you build full-text search patterns suitable for prefix queries. -- **New**: `FTS3.tokenize(_:)` and `FTS5.tokenize(_:)` let you tokenize input strings. +- **New**: `FTS3.tokenize(_:)` and `FTS5Tokenizer.tokenize(_:)` let you tokenize input strings. +- **Documentation Update**: Full-text search documentation was updated for the new search pattern initializers ([FTS3/4](Documentation/FullTextSearch.md#fts3pattern), [FTS5](Documentation/FullTextSearch.md#fts5pattern)), and tokenization methods ([FTS3/4](Documentation/FullTextSearch.md#fts3-and-fts4-tokenization), [FTS5](Documentation/FullTextSearch.md#fts5-tokenization)). ## 5.11.0 diff --git a/Documentation/FullTextSearch.md b/Documentation/FullTextSearch.md index 4d36f9999..0bf70a2b6 100644 --- a/Documentation/FullTextSearch.md +++ b/Documentation/FullTextSearch.md @@ -31,6 +31,7 @@ let books = try Book.fetchAll(db, - **[Enabling FTS5 Support](#enabling-fts5-support)** - **Create Full-Text Virtual Tables**: [FTS3/4](#create-fts3-and-fts4-virtual-tables), [FTS5](#create-fts5-virtual-tables) - **Choosing a Tokenizer**: [FTS3/4](#fts3-and-fts4-tokenizers), [FTS5](#fts5-tokenizers) +- **Tokenization**: [FTS3/4](#fts3-and-fts4-tokenization), [FTS5](#fts5-tokenization) - **Search Patterns**: [FTS3/4](#fts3pattern), [FTS5](#fts5pattern) - **Sorting by Relevance**: [FTS5](#fts5-sorting-by-relevance) - **External Content Full-Text Tables**: [FTS4/5](#external-content-full-text-tables) @@ -226,6 +227,11 @@ See below some examples of matches: It does not provide stemming, and won't match "databases" with "database". +See [SQLite tokenizers](https://www.sqlite.org/fts3.html#tokenizer) for more information. + + +## FTS3 and FTS4 Tokenization + You can tokenize strings when needed: ```swift @@ -238,8 +244,6 @@ FTS3.tokenize("SQLite database", withTokenizer: .porter) // ["sqlite", "databa FTS3.tokenize("Gustave Doré", withTokenizer: .unicode61()) // ["gustave", "dore"]) ``` -See [SQLite tokenizers](https://www.sqlite.org/fts3.html#tokenizer) for more information. - ## FTS3Pattern @@ -488,19 +492,30 @@ See below some examples of matches: It strips diacritics from latin script characters if it wraps unicode61, and does not if it wraps ascii (see the example above). +See [SQLite tokenizers](https://www.sqlite.org/fts5.html#tokenizers) for more information, and [custom FTS5 tokenizers](FTS5Tokenizers.md) in order to add your own tokenizers. + + +## FTS5 Tokenization + You can tokenize strings when needed: ```swift -// Default tokenization using the `ascii` tokenizer: -try FTS5.tokenize("SQLite database") // ["sqlite", "database"] -try FTS5.tokenize("Gustave Doré") // ["gustave", "doré"]) +let ascii = try db.makeTokenizer(.ascii()) -// Tokenization with an explicit tokenizer: -try FTS5.tokenize("SQLite database", withTokenizer: .porter()) // ["sqlite", "databas"] -try FTS5.tokenize("Gustave Doré", withTokenizer: .unicode61()) // ["gustave", "dore"]) +// Tokenize an FTS5 query +for (token, flags) in try ascii.tokenize(query: "SQLite database") { + print(token) // Prints "sqlite" then "database" +} + +// Tokenize an FTS5 document +for (token, flags) in try ascii.tokenize(document: "SQLite database") { + print(token) // Prints "sqlite" then "database" +} ``` -See [SQLite tokenizers](https://www.sqlite.org/fts5.html#tokenizers) for more information, and [custom FTS5 tokenizers](FTS5Tokenizers.md) in order to add your own tokenizers. +Some tokenizers may produce a different output when you tokenize a query or a document (see `FTS5_TOKENIZE_QUERY` and `FTS5_TOKENIZE_DOCUMENT` in https://www.sqlite.org/fts5.html#custom_tokenizers). You should generally use `tokenize(query:)` when you intend to tokenize a string in order to compose a [raw search pattern](#fts5pattern). + +See the `FTS5_TOKEN_*` flags in https://www.sqlite.org/fts5.html#custom_tokenizers for more information about token flags. In particular, tokenizers that support synonyms may output multiple tokens for a single word, along with the `.colocated` flag. ## FTS5Pattern diff --git a/GRDB/FTS/FTS5.swift b/GRDB/FTS/FTS5.swift index e9bd7d93e..3669a52d4 100644 --- a/GRDB/FTS/FTS5.swift +++ b/GRDB/FTS/FTS5.swift @@ -46,37 +46,28 @@ public struct FTS5: VirtualTableModule { /// See public init() { } - /// Returns an array of tokens found in the string argument. + // Support for FTS5Pattern initializers. Don't make public. Users tokenize + // with `FTS5Tokenizer.tokenize()` methods, which support custom tokenizers, + // token flags, and query/document tokenzation. + /// Tokenizes the string argument as an FTS5 query. /// /// For example: /// - /// try FTS5.tokenize("SQLite database") // ["sqlite", "database"] - /// try FTS5.tokenize("Gustave Doré") // ["gustave", "doré"]) - /// - /// Results can be altered with an explicit tokenizer - default is `.ascii()`. - /// See . - /// - /// try FTS5.tokenize("SQLite database", withTokenizer: .porter()) // ["sqlite", "databas"] - /// try FTS5.tokenize("Gustave Doré", withTokenizer: .unicode61()) // ["gustave", "dore"]) + /// try FTS5.tokenize(query: "SQLite database") // ["sqlite", "database"] + /// try FTS5.tokenize(query: "Gustave Doré") // ["gustave", "doré"]) /// /// Synonym (colocated) tokens are not present in the returned array. See /// `FTS5_TOKEN_COLOCATED` at /// for more information. /// /// - parameter string: The tokenized string. - /// - parameter tokenizer: The tokenizer - defaults to `.ascii()`. - /// - parameter tokenization: The reason why tokenization is requested - - /// defaults to `.query`. /// - returns: An array of tokens. /// - throws: An error if tokenization fails. - public static func tokenize( - _ string: String, - withTokenizer tokenizer: FTS5TokenizerDescriptor = .ascii(), - for tokenization: FTS5Tokenization = .query) - throws -> [String] - { + static func tokenize(query string: String) throws -> [String] { try DatabaseQueue().inDatabase { db in - try db.makeTokenizer(tokenizer).nonSynonymTokens(in: string, for: tokenization) + try db.makeTokenizer(.ascii()).tokenize(query: string).compactMap { + $0.flags.contains(.colocated) ? nil : $0.token + } } } diff --git a/GRDB/FTS/FTS5Pattern.swift b/GRDB/FTS/FTS5Pattern.swift index d746895c7..e1852f58a 100644 --- a/GRDB/FTS/FTS5Pattern.swift +++ b/GRDB/FTS/FTS5Pattern.swift @@ -13,9 +13,9 @@ public struct FTS5Pattern { /// /// - parameter string: The string to turn into an FTS5 pattern public init?(matchingAnyTokenIn string: String) { - guard let tokens = try? FTS5.tokenize(string, withTokenizer: .ascii(), for: .query), - !tokens.isEmpty - else { return nil } + guard let tokens = try? FTS5.tokenize(query: string), !tokens.isEmpty else { + return nil + } try? self.init(rawPattern: tokens.joined(separator: " OR ")) } @@ -27,9 +27,9 @@ public struct FTS5Pattern { /// /// - parameter string: The string to turn into an FTS5 pattern public init?(matchingAllTokensIn string: String) { - guard let tokens = try? FTS5.tokenize(string, withTokenizer: .ascii(), for: .query), - !tokens.isEmpty - else { return nil } + guard let tokens = try? FTS5.tokenize(query: string), !tokens.isEmpty else { + return nil + } try? self.init(rawPattern: tokens.joined(separator: " ")) } @@ -41,9 +41,9 @@ public struct FTS5Pattern { /// /// - parameter string: The string to turn into an FTS3 pattern public init?(matchingAllPrefixesIn string: String) { - guard let tokens = try? FTS5.tokenize(string, withTokenizer: .ascii(), for: .query), - !tokens.isEmpty - else { return nil } + guard let tokens = try? FTS5.tokenize(query: string), !tokens.isEmpty else { + return nil + } try? self.init(rawPattern: tokens.map { "\($0)*" }.joined(separator: " ")) } @@ -55,9 +55,9 @@ public struct FTS5Pattern { /// /// - parameter string: The string to turn into an FTS5 pattern public init?(matchingPhrase string: String) { - guard let tokens = try? FTS5.tokenize(string, withTokenizer: .ascii(), for: .query), - !tokens.isEmpty - else { return nil } + guard let tokens = try? FTS5.tokenize(query: string), !tokens.isEmpty else { + return nil + } try? self.init(rawPattern: "\"" + tokens.joined(separator: " ") + "\"") } @@ -72,9 +72,9 @@ public struct FTS5Pattern { /// /// - parameter string: The string to turn into an FTS5 pattern public init?(matchingPrefixPhrase string: String) { - guard let tokens = try? FTS5.tokenize(string, withTokenizer: .ascii(), for: .query), - !tokens.isEmpty - else { return nil } + guard let tokens = try? FTS5.tokenize(query: string), !tokens.isEmpty else { + return nil + } try? self.init(rawPattern: "^\"" + tokens.joined(separator: " ") + "\"") } diff --git a/GRDB/FTS/FTS5Tokenizer.swift b/GRDB/FTS/FTS5Tokenizer.swift index fd94116fe..551270802 100644 --- a/GRDB/FTS/FTS5Tokenizer.swift +++ b/GRDB/FTS/FTS5Tokenizer.swift @@ -67,8 +67,40 @@ private class TokenizeContext { extension FTS5Tokenizer { - /// Tokenizes the string argument into an array of - /// (String, FTS5TokenFlags) pairs. + /// Tokenizes the string argument as a document that would be inserted into + /// an FTS5 table. + /// + /// For example: + /// + /// let tokenizer = try db.makeTokenizer(.ascii()) + /// try tokenizer.tokenize(document: "foo bar") // [("foo", flags), ("bar", flags)] + /// + /// See also `tokenize(query:)`. + /// + /// - parameter string: The string to tokenize. + /// - returns: An array of tokens and flags. + /// - throws: An error if tokenization fails. + public func tokenize(document string: String) throws -> [(token: String, flags: FTS5TokenFlags)] { + try tokenize(string, for: .document) + } + + /// Tokenizes the string argument as an FTS5 query. + /// + /// For example: + /// + /// let tokenizer = try db.makeTokenizer(.ascii()) + /// try tokenizer.tokenize(query: "foo bar") // [("foo", flags), ("bar", flags)] + /// + /// See also `tokenize(document:)`. + /// + /// - parameter string: The string to tokenize. + /// - returns: An array of tokens and flags. + /// - throws: An error if tokenization fails. + public func tokenize(query string: String) throws -> [(token: String, flags: FTS5TokenFlags)] { + try tokenize(string, for: .query) + } + + /// Tokenizes the string argument. /// /// let tokenizer = try db.makeTokenizer(.ascii()) /// try tokenizer.tokenize("foo bar", for: .document) // [("foo", flags), ("bar", flags)] @@ -78,7 +110,9 @@ extension FTS5Tokenizer { /// - .document: Tokenize like a document being inserted into an FTS table. /// - .query: Tokenize like the search pattern of the MATCH operator. /// - parameter tokenizer: A FTS5TokenizerDescriptor such as .ascii() - func tokenize(_ string: String, for tokenization: FTS5Tokenization) throws -> [(String, FTS5TokenFlags)] { + private func tokenize(_ string: String, for tokenization: FTS5Tokenization) + throws -> [(token: String, flags: FTS5TokenFlags)] + { try ContiguousArray(string.utf8).withUnsafeBufferPointer { buffer -> [(String, FTS5TokenFlags)] in guard let addr = buffer.baseAddress else { return [] @@ -120,16 +154,6 @@ extension FTS5Tokenizer { return context.tokens } } - - func nonSynonymTokens(in string: String, for tokenization: FTS5Tokenization) throws -> [String] { - var tokens: [String] = [] - for (token, flags) in try tokenize(string, for: tokenization) { - if !flags.contains(.colocated) { - tokens.append(token) - } - } - return tokens - } } extension Database { diff --git a/GRDB/FTS/FTS5WrapperTokenizer.swift b/GRDB/FTS/FTS5WrapperTokenizer.swift index 9c9093de6..dfee9e0bd 100644 --- a/GRDB/FTS/FTS5WrapperTokenizer.swift +++ b/GRDB/FTS/FTS5WrapperTokenizer.swift @@ -3,7 +3,7 @@ import Foundation /// Flags that tell SQLite how to register a token. /// -/// See +/// See the `FTS5_TOKEN_*` flags in . public struct FTS5TokenFlags: OptionSet { public let rawValue: Int32 diff --git a/Tests/GRDBTests/FTS3PatternTests.swift b/Tests/GRDBTests/FTS3PatternTests.swift index 27ade619e..2e79a0f5c 100644 --- a/Tests/GRDBTests/FTS3PatternTests.swift +++ b/Tests/GRDBTests/FTS3PatternTests.swift @@ -65,92 +65,6 @@ class FTS3PatternTests: GRDBTestCase { } } - func testFTS3Tokenize() { - // Empty query - XCTAssertEqual(FTS3.tokenize(""), []) - XCTAssertEqual(FTS3.tokenize("", withTokenizer: .simple), []) - XCTAssertEqual(FTS3.tokenize("", withTokenizer: .porter), []) - XCTAssertEqual(FTS3.tokenize("", withTokenizer: .unicode61()), []) - XCTAssertEqual(FTS3.tokenize("", withTokenizer: .unicode61(diacritics: .keep)), []) - - XCTAssertEqual(FTS3.tokenize("?!"), []) - XCTAssertEqual(FTS3.tokenize("?!", withTokenizer: .simple), []) - XCTAssertEqual(FTS3.tokenize("?!", withTokenizer: .porter), []) - XCTAssertEqual(FTS3.tokenize("?!", withTokenizer: .unicode61()), []) - XCTAssertEqual(FTS3.tokenize("?!", withTokenizer: .unicode61(diacritics: .keep)), []) - - // Token queries - XCTAssertEqual(FTS3.tokenize("Moby"), ["moby"]) - XCTAssertEqual(FTS3.tokenize("Moby", withTokenizer: .simple), ["moby"]) - XCTAssertEqual(FTS3.tokenize("Moby", withTokenizer: .porter), ["mobi"]) - XCTAssertEqual(FTS3.tokenize("Moby", withTokenizer: .unicode61()), ["moby"]) - XCTAssertEqual(FTS3.tokenize("Moby", withTokenizer: .unicode61(diacritics: .keep)), ["moby"]) - - XCTAssertEqual(FTS3.tokenize("écarlates"), ["écarlates"]) - XCTAssertEqual(FTS3.tokenize("écarlates", withTokenizer: .simple), ["écarlates"]) - XCTAssertEqual(FTS3.tokenize("écarlates", withTokenizer: .porter), ["écarlates"]) - XCTAssertEqual(FTS3.tokenize("écarlates", withTokenizer: .unicode61()), ["ecarlates"]) - XCTAssertEqual(FTS3.tokenize("écarlates", withTokenizer: .unicode61(diacritics: .keep)), ["écarlates"]) - - XCTAssertEqual(FTS3.tokenize("fooéı👨👨🏿🇫🇷🇨🇮"), ["fooéı👨👨🏿🇫🇷🇨🇮"]) - XCTAssertEqual(FTS3.tokenize("fooéı👨👨🏿🇫🇷🇨🇮", withTokenizer: .simple), ["fooéı👨👨🏿🇫🇷🇨🇮"]) - XCTAssertEqual(FTS3.tokenize("fooéı👨👨🏿🇫🇷🇨🇮", withTokenizer: .porter), ["fooéı👇�🇨🇮"]) // ¯\_(ツ)_/¯ - XCTAssertEqual(FTS3.tokenize("fooéı👨👨🏿🇫🇷🇨🇮", withTokenizer: .unicode61()), ["fooeı", "🏿"]) // ¯\_(ツ)_/¯ - XCTAssertEqual(FTS3.tokenize("fooéı👨👨🏿🇫🇷🇨🇮", withTokenizer: .unicode61(diacritics: .keep)), ["fooéı", "🏿"]) // ¯\_(ツ)_/¯ - - XCTAssertEqual(FTS3.tokenize("SQLite database"), ["sqlite", "database"]) - XCTAssertEqual(FTS3.tokenize("SQLite database", withTokenizer: .simple), ["sqlite", "database"]) - XCTAssertEqual(FTS3.tokenize("SQLite database", withTokenizer: .porter), ["sqlite", "databas"]) - XCTAssertEqual(FTS3.tokenize("SQLite database", withTokenizer: .unicode61()), ["sqlite", "database"]) - XCTAssertEqual(FTS3.tokenize("SQLite database", withTokenizer: .unicode61(diacritics: .keep)), ["sqlite", "database"]) - - XCTAssertEqual(FTS3.tokenize("Édouard Manet"), ["Édouard", "manet"]) - XCTAssertEqual(FTS3.tokenize("Édouard Manet", withTokenizer: .simple), ["Édouard", "manet"]) - XCTAssertEqual(FTS3.tokenize("Édouard Manet", withTokenizer: .porter), ["Édouard", "manet"]) - XCTAssertEqual(FTS3.tokenize("Édouard Manet", withTokenizer: .unicode61()), ["edouard", "manet"]) - XCTAssertEqual(FTS3.tokenize("Édouard Manet", withTokenizer: .unicode61(diacritics: .keep)), ["édouard", "manet"]) - - // Prefix queries - XCTAssertEqual(FTS3.tokenize("*"), []) - XCTAssertEqual(FTS3.tokenize("*", withTokenizer: .simple), []) - XCTAssertEqual(FTS3.tokenize("*", withTokenizer: .porter), []) - XCTAssertEqual(FTS3.tokenize("*", withTokenizer: .unicode61()), []) - XCTAssertEqual(FTS3.tokenize("*", withTokenizer: .unicode61(diacritics: .keep)), []) - - XCTAssertEqual(FTS3.tokenize("Robin*"), ["robin"]) - XCTAssertEqual(FTS3.tokenize("Robin*", withTokenizer: .simple), ["robin"]) - XCTAssertEqual(FTS3.tokenize("Robin*", withTokenizer: .porter), ["robin"]) - XCTAssertEqual(FTS3.tokenize("Robin*", withTokenizer: .unicode61()), ["robin"]) - XCTAssertEqual(FTS3.tokenize("Robin*", withTokenizer: .unicode61(diacritics: .keep)), ["robin"]) - - // Phrase queries - XCTAssertEqual(FTS3.tokenize("\"foulent muscles\""), ["foulent", "muscles"]) - XCTAssertEqual(FTS3.tokenize("\"foulent muscles\"", withTokenizer: .simple), ["foulent", "muscles"]) - XCTAssertEqual(FTS3.tokenize("\"foulent muscles\"", withTokenizer: .porter), ["foulent", "muscl"]) - XCTAssertEqual(FTS3.tokenize("\"foulent muscles\"", withTokenizer: .unicode61()), ["foulent", "muscles"]) - XCTAssertEqual(FTS3.tokenize("\"foulent muscles\"", withTokenizer: .unicode61(diacritics: .keep)), ["foulent", "muscles"]) - - XCTAssertEqual(FTS3.tokenize("\"Kim Stan* Robin*\""), ["kim", "stan", "robin"]) - XCTAssertEqual(FTS3.tokenize("\"Kim Stan* Robin*\"", withTokenizer: .simple), ["kim", "stan", "robin"]) - XCTAssertEqual(FTS3.tokenize("\"Kim Stan* Robin*\"", withTokenizer: .porter), ["kim", "stan", "robin"]) - XCTAssertEqual(FTS3.tokenize("\"Kim Stan* Robin*\"", withTokenizer: .unicode61()), ["kim", "stan", "robin"]) - XCTAssertEqual(FTS3.tokenize("\"Kim Stan* Robin*\"", withTokenizer: .unicode61(diacritics: .keep)), ["kim", "stan", "robin"]) - - // Logical queries - XCTAssertEqual(FTS3.tokenize("years AND months"), ["years", "and", "months"]) - XCTAssertEqual(FTS3.tokenize("years AND months", withTokenizer: .simple), ["years", "and", "months"]) - XCTAssertEqual(FTS3.tokenize("years AND months", withTokenizer: .porter), ["year", "and", "month"]) - XCTAssertEqual(FTS3.tokenize("years AND months", withTokenizer: .unicode61()), ["years", "and", "months"]) - XCTAssertEqual(FTS3.tokenize("years AND months", withTokenizer: .unicode61(diacritics: .keep)), ["years", "and", "months"]) - - // column queries - XCTAssertEqual(FTS3.tokenize("title:brest"), ["title", "brest"]) - XCTAssertEqual(FTS3.tokenize("title:brest", withTokenizer: .simple), ["title", "brest"]) - XCTAssertEqual(FTS3.tokenize("title:brest", withTokenizer: .porter), ["titl", "brest"]) - XCTAssertEqual(FTS3.tokenize("title:brest", withTokenizer: .unicode61()), ["title", "brest"]) - XCTAssertEqual(FTS3.tokenize("title:brest", withTokenizer: .unicode61(diacritics: .keep)), ["title", "brest"]) - } - func testFTS3PatternWithAnyToken() throws { let wrongInputs = ["", "*", "^", " ", "(", "()", "\"", "?!"] for string in wrongInputs { diff --git a/Tests/GRDBTests/FTS3TokenizerTests.swift b/Tests/GRDBTests/FTS3TokenizerTests.swift index 5a0cdd10d..4e140db87 100644 --- a/Tests/GRDBTests/FTS3TokenizerTests.swift +++ b/Tests/GRDBTests/FTS3TokenizerTests.swift @@ -144,4 +144,90 @@ class FTS3TokenizerTests: GRDBTestCase { XCTAssertFalse(match(db, "2016-10-04.txt", "txt")) } } + + func testTokenize() { + // Empty query + XCTAssertEqual(FTS3.tokenize(""), []) + XCTAssertEqual(FTS3.tokenize("", withTokenizer: .simple), []) + XCTAssertEqual(FTS3.tokenize("", withTokenizer: .porter), []) + XCTAssertEqual(FTS3.tokenize("", withTokenizer: .unicode61()), []) + XCTAssertEqual(FTS3.tokenize("", withTokenizer: .unicode61(diacritics: .keep)), []) + + XCTAssertEqual(FTS3.tokenize("?!"), []) + XCTAssertEqual(FTS3.tokenize("?!", withTokenizer: .simple), []) + XCTAssertEqual(FTS3.tokenize("?!", withTokenizer: .porter), []) + XCTAssertEqual(FTS3.tokenize("?!", withTokenizer: .unicode61()), []) + XCTAssertEqual(FTS3.tokenize("?!", withTokenizer: .unicode61(diacritics: .keep)), []) + + // Token queries + XCTAssertEqual(FTS3.tokenize("Moby"), ["moby"]) + XCTAssertEqual(FTS3.tokenize("Moby", withTokenizer: .simple), ["moby"]) + XCTAssertEqual(FTS3.tokenize("Moby", withTokenizer: .porter), ["mobi"]) + XCTAssertEqual(FTS3.tokenize("Moby", withTokenizer: .unicode61()), ["moby"]) + XCTAssertEqual(FTS3.tokenize("Moby", withTokenizer: .unicode61(diacritics: .keep)), ["moby"]) + + XCTAssertEqual(FTS3.tokenize("écarlates"), ["écarlates"]) + XCTAssertEqual(FTS3.tokenize("écarlates", withTokenizer: .simple), ["écarlates"]) + XCTAssertEqual(FTS3.tokenize("écarlates", withTokenizer: .porter), ["écarlates"]) + XCTAssertEqual(FTS3.tokenize("écarlates", withTokenizer: .unicode61()), ["ecarlates"]) + XCTAssertEqual(FTS3.tokenize("écarlates", withTokenizer: .unicode61(diacritics: .keep)), ["écarlates"]) + + XCTAssertEqual(FTS3.tokenize("fooéı👨👨🏿🇫🇷🇨🇮"), ["fooéı👨👨🏿🇫🇷🇨🇮"]) + XCTAssertEqual(FTS3.tokenize("fooéı👨👨🏿🇫🇷🇨🇮", withTokenizer: .simple), ["fooéı👨👨🏿🇫🇷🇨🇮"]) + XCTAssertEqual(FTS3.tokenize("fooéı👨👨🏿🇫🇷🇨🇮", withTokenizer: .porter), ["fooéı👇�🇨🇮"]) // ¯\_(ツ)_/¯ + XCTAssertEqual(FTS3.tokenize("fooéı👨👨🏿🇫🇷🇨🇮", withTokenizer: .unicode61()), ["fooeı", "🏿"]) // ¯\_(ツ)_/¯ + XCTAssertEqual(FTS3.tokenize("fooéı👨👨🏿🇫🇷🇨🇮", withTokenizer: .unicode61(diacritics: .keep)), ["fooéı", "🏿"]) // ¯\_(ツ)_/¯ + + XCTAssertEqual(FTS3.tokenize("SQLite database"), ["sqlite", "database"]) + XCTAssertEqual(FTS3.tokenize("SQLite database", withTokenizer: .simple), ["sqlite", "database"]) + XCTAssertEqual(FTS3.tokenize("SQLite database", withTokenizer: .porter), ["sqlite", "databas"]) + XCTAssertEqual(FTS3.tokenize("SQLite database", withTokenizer: .unicode61()), ["sqlite", "database"]) + XCTAssertEqual(FTS3.tokenize("SQLite database", withTokenizer: .unicode61(diacritics: .keep)), ["sqlite", "database"]) + + XCTAssertEqual(FTS3.tokenize("Édouard Manet"), ["Édouard", "manet"]) + XCTAssertEqual(FTS3.tokenize("Édouard Manet", withTokenizer: .simple), ["Édouard", "manet"]) + XCTAssertEqual(FTS3.tokenize("Édouard Manet", withTokenizer: .porter), ["Édouard", "manet"]) + XCTAssertEqual(FTS3.tokenize("Édouard Manet", withTokenizer: .unicode61()), ["edouard", "manet"]) + XCTAssertEqual(FTS3.tokenize("Édouard Manet", withTokenizer: .unicode61(diacritics: .keep)), ["édouard", "manet"]) + + // Prefix queries + XCTAssertEqual(FTS3.tokenize("*"), []) + XCTAssertEqual(FTS3.tokenize("*", withTokenizer: .simple), []) + XCTAssertEqual(FTS3.tokenize("*", withTokenizer: .porter), []) + XCTAssertEqual(FTS3.tokenize("*", withTokenizer: .unicode61()), []) + XCTAssertEqual(FTS3.tokenize("*", withTokenizer: .unicode61(diacritics: .keep)), []) + + XCTAssertEqual(FTS3.tokenize("Robin*"), ["robin"]) + XCTAssertEqual(FTS3.tokenize("Robin*", withTokenizer: .simple), ["robin"]) + XCTAssertEqual(FTS3.tokenize("Robin*", withTokenizer: .porter), ["robin"]) + XCTAssertEqual(FTS3.tokenize("Robin*", withTokenizer: .unicode61()), ["robin"]) + XCTAssertEqual(FTS3.tokenize("Robin*", withTokenizer: .unicode61(diacritics: .keep)), ["robin"]) + + // Phrase queries + XCTAssertEqual(FTS3.tokenize("\"foulent muscles\""), ["foulent", "muscles"]) + XCTAssertEqual(FTS3.tokenize("\"foulent muscles\"", withTokenizer: .simple), ["foulent", "muscles"]) + XCTAssertEqual(FTS3.tokenize("\"foulent muscles\"", withTokenizer: .porter), ["foulent", "muscl"]) + XCTAssertEqual(FTS3.tokenize("\"foulent muscles\"", withTokenizer: .unicode61()), ["foulent", "muscles"]) + XCTAssertEqual(FTS3.tokenize("\"foulent muscles\"", withTokenizer: .unicode61(diacritics: .keep)), ["foulent", "muscles"]) + + XCTAssertEqual(FTS3.tokenize("\"Kim Stan* Robin*\""), ["kim", "stan", "robin"]) + XCTAssertEqual(FTS3.tokenize("\"Kim Stan* Robin*\"", withTokenizer: .simple), ["kim", "stan", "robin"]) + XCTAssertEqual(FTS3.tokenize("\"Kim Stan* Robin*\"", withTokenizer: .porter), ["kim", "stan", "robin"]) + XCTAssertEqual(FTS3.tokenize("\"Kim Stan* Robin*\"", withTokenizer: .unicode61()), ["kim", "stan", "robin"]) + XCTAssertEqual(FTS3.tokenize("\"Kim Stan* Robin*\"", withTokenizer: .unicode61(diacritics: .keep)), ["kim", "stan", "robin"]) + + // Logical queries + XCTAssertEqual(FTS3.tokenize("years AND months"), ["years", "and", "months"]) + XCTAssertEqual(FTS3.tokenize("years AND months", withTokenizer: .simple), ["years", "and", "months"]) + XCTAssertEqual(FTS3.tokenize("years AND months", withTokenizer: .porter), ["year", "and", "month"]) + XCTAssertEqual(FTS3.tokenize("years AND months", withTokenizer: .unicode61()), ["years", "and", "months"]) + XCTAssertEqual(FTS3.tokenize("years AND months", withTokenizer: .unicode61(diacritics: .keep)), ["years", "and", "months"]) + + // column queries + XCTAssertEqual(FTS3.tokenize("title:brest"), ["title", "brest"]) + XCTAssertEqual(FTS3.tokenize("title:brest", withTokenizer: .simple), ["title", "brest"]) + XCTAssertEqual(FTS3.tokenize("title:brest", withTokenizer: .porter), ["titl", "brest"]) + XCTAssertEqual(FTS3.tokenize("title:brest", withTokenizer: .unicode61()), ["title", "brest"]) + XCTAssertEqual(FTS3.tokenize("title:brest", withTokenizer: .unicode61(diacritics: .keep)), ["title", "brest"]) + } } diff --git a/Tests/GRDBTests/FTS5CustomTokenizerTests.swift b/Tests/GRDBTests/FTS5CustomTokenizerTests.swift index 710916dfe..cc89a3487 100644 --- a/Tests/GRDBTests/FTS5CustomTokenizerTests.swift +++ b/Tests/GRDBTests/FTS5CustomTokenizerTests.swift @@ -121,7 +121,7 @@ private final class SynonymsTokenizer : FTS5CustomTokenizer { static let name = "synonyms" let wrappedTokenizer: FTS5Tokenizer let synonyms: [Set] - + init(db: Database, arguments: [String]) throws { if arguments.isEmpty { wrappedTokenizer = try db.makeTokenizer(.unicode61()) @@ -130,11 +130,11 @@ private final class SynonymsTokenizer : FTS5CustomTokenizer { } synonyms = [["first", "1st"]] } - + deinit { // TODO: test that deinit is called } - + func tokenize(context: UnsafeMutableRawPointer?, tokenization: FTS5Tokenization, pText: UnsafePointer?, nText: Int32, tokenCallback: @escaping FTS5TokenCallback) -> Int32 { // Don't look for synonyms when tokenizing queries, as advised by // https://www.sqlite.org/fts5.html#synonym_support @@ -153,7 +153,7 @@ private final class SynonymsTokenizer : FTS5CustomTokenizer { let tokenCallback: FTS5TokenCallback } var customContext = CustomContext(synonyms: synonyms, context: context!, tokenCallback: tokenCallback) - + return withUnsafeMutablePointer(to: &customContext) { customContextPointer in // Invoke wrappedTokenizer, but intercept raw tokens return wrappedTokenizer.tokenize(context: customContextPointer, tokenization: tokenization, pText: pText, nText: nText) { (customContextPointer, flags, pToken, nToken, iStart, iEnd) in @@ -165,7 +165,7 @@ private final class SynonymsTokenizer : FTS5CustomTokenizer { return 0 // SQLITE_OK } - guard let synonyms = customContext.synonyms.first(where: { $0.contains(token) }) else { + guard let synonyms = customContext.synonyms.first(where: { $0.contains(token) })?.sorted() else { // No synonym return customContext.tokenCallback(customContext.context, flags, pToken, nToken, iStart, iEnd) } @@ -214,7 +214,7 @@ class FTS5CustomTokenizerTests: GRDBTestCase { XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"foo bar baz\""]), 1) } } - + func testStopWordsTokenizerDatabasePool() throws { dbConfiguration.prepareDatabase { db in db.add(tokenizer: StopWordsTokenizer.self) @@ -246,7 +246,15 @@ class FTS5CustomTokenizerTests: GRDBTestCase { XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["\"foo bar baz\""]), 1) } } - + + func testStopWordsTokenizer_tokenize() throws { + try makeDatabaseQueue().inDatabase { db in + db.add(tokenizer: StopWordsTokenizer.self) + let tokenizer = try db.makeTokenizer(StopWordsTokenizer.tokenizerDescriptor()) + try XCTAssertEqual(tokenizer.tokenize(query: "foo bar baz").map(\.token), ["foo", "baz"]) + } + } + func testNFKCTokenizer() throws { let dbQueue = try makeDatabaseQueue() @@ -303,7 +311,15 @@ class FTS5CustomTokenizerTests: GRDBTestCase { try db.drop(table: "documents") } } - + + func testNFKCTokenizer_tokenize() throws { + try makeDatabaseQueue().inDatabase { db in + db.add(tokenizer: NFKCTokenizer.self) + let tokenizer = try db.makeTokenizer(NFKCTokenizer.tokenizerDescriptor()) + try XCTAssertEqual(tokenizer.tokenize(query: "foo aimé\u{FB01}").map(\.token), ["foo", "aimefi"]) // U+FB01: LATIN SMALL LIGATURE FI + } + } + func testSynonymTokenizer() throws { let dbQueue = try makeDatabaseQueue() @@ -327,5 +343,18 @@ class FTS5CustomTokenizerTests: GRDBTestCase { XCTAssertEqual(try Int.fetchOne(db, sql: "SELECT COUNT(*) FROM documents WHERE documents MATCH ?", arguments: ["1s*"]), 2) } } + + func testSynonymsTokenizer_tokenize() throws { + try makeDatabaseQueue().inDatabase { db in + db.add(tokenizer: SynonymsTokenizer.self) + let tokenizer = try db.makeTokenizer(SynonymsTokenizer.tokenizerDescriptor()) + + try XCTAssertEqual(tokenizer.tokenize(query: "foo first 1st").map(\.token), ["foo", "first", "1st"]) + try XCTAssertEqual(tokenizer.tokenize(query: "foo first 1st").map(\.flags), [[], [], []]) + + try XCTAssertEqual(tokenizer.tokenize(document: "foo first 1st").map(\.token), ["foo", "1st", "first", "1st", "first"]) + try XCTAssertEqual(tokenizer.tokenize(document: "foo first 1st").map(\.flags), [[], [], .colocated, [], .colocated]) + } + } } #endif diff --git a/Tests/GRDBTests/FTS5PatternTests.swift b/Tests/GRDBTests/FTS5PatternTests.swift index 42b101f32..ec9478c29 100644 --- a/Tests/GRDBTests/FTS5PatternTests.swift +++ b/Tests/GRDBTests/FTS5PatternTests.swift @@ -50,92 +50,6 @@ class FTS5PatternTests: GRDBTestCase { } } - func testFTS5Tokenize() throws { - // Empty query - try XCTAssertEqual(FTS5.tokenize(""), []) - try XCTAssertEqual(FTS5.tokenize("", withTokenizer: .ascii()), []) - try XCTAssertEqual(FTS5.tokenize("", withTokenizer: .porter()), []) - try XCTAssertEqual(FTS5.tokenize("", withTokenizer: .unicode61()), []) - try XCTAssertEqual(FTS5.tokenize("", withTokenizer: .unicode61(diacritics: .keep)), []) - - try XCTAssertEqual(FTS5.tokenize("?!"), []) - try XCTAssertEqual(FTS5.tokenize("?!", withTokenizer: .ascii()), []) - try XCTAssertEqual(FTS5.tokenize("?!", withTokenizer: .porter()), []) - try XCTAssertEqual(FTS5.tokenize("?!", withTokenizer: .unicode61()), []) - try XCTAssertEqual(FTS5.tokenize("?!", withTokenizer: .unicode61(diacritics: .keep)), []) - - // Token queries - try XCTAssertEqual(FTS5.tokenize("Moby"), ["moby"]) - try XCTAssertEqual(FTS5.tokenize("Moby", withTokenizer: .ascii()), ["moby"]) - try XCTAssertEqual(FTS5.tokenize("Moby", withTokenizer: .porter()), ["mobi"]) - try XCTAssertEqual(FTS5.tokenize("Moby", withTokenizer: .unicode61()), ["moby"]) - try XCTAssertEqual(FTS5.tokenize("Moby", withTokenizer: .unicode61(diacritics: .keep)), ["moby"]) - - try XCTAssertEqual(FTS5.tokenize("écarlates"), ["écarlates"]) - try XCTAssertEqual(FTS5.tokenize("écarlates", withTokenizer: .ascii()), ["écarlates"]) - try XCTAssertEqual(FTS5.tokenize("écarlates", withTokenizer: .porter()), ["ecarl"]) - try XCTAssertEqual(FTS5.tokenize("écarlates", withTokenizer: .unicode61()), ["ecarlates"]) - try XCTAssertEqual(FTS5.tokenize("écarlates", withTokenizer: .unicode61(diacritics: .keep)), ["écarlates"]) - - try XCTAssertEqual(FTS5.tokenize("fooéı👨👨🏿🇫🇷🇨🇮"), ["fooéı👨👨🏿🇫🇷🇨🇮"]) - try XCTAssertEqual(FTS5.tokenize("fooéı👨👨🏿🇫🇷🇨🇮", withTokenizer: .ascii()), ["fooéı👨👨🏿🇫🇷🇨🇮"]) - try XCTAssertEqual(FTS5.tokenize("fooéı👨👨🏿🇫🇷🇨🇮", withTokenizer: .porter()), ["fooeı", "🏿"]) // ¯\_(ツ)_/¯ - try XCTAssertEqual(FTS5.tokenize("fooéı👨👨🏿🇫🇷🇨🇮", withTokenizer: .unicode61()), ["fooeı", "🏿"]) // ¯\_(ツ)_/¯ - try XCTAssertEqual(FTS5.tokenize("fooéı👨👨🏿🇫🇷🇨🇮", withTokenizer: .unicode61(diacritics: .keep)), ["fooéı", "🏿"]) // ¯\_(ツ)_/¯ - - try XCTAssertEqual(FTS5.tokenize("SQLite database"), ["sqlite", "database"]) - try XCTAssertEqual(FTS5.tokenize("SQLite database", withTokenizer: .ascii()), ["sqlite", "database"]) - try XCTAssertEqual(FTS5.tokenize("SQLite database", withTokenizer: .porter()), ["sqlite", "databas"]) - try XCTAssertEqual(FTS5.tokenize("SQLite database", withTokenizer: .unicode61()), ["sqlite", "database"]) - try XCTAssertEqual(FTS5.tokenize("SQLite database", withTokenizer: .unicode61(diacritics: .keep)), ["sqlite", "database"]) - - try XCTAssertEqual(FTS5.tokenize("Édouard Manet"), ["Édouard", "manet"]) - try XCTAssertEqual(FTS5.tokenize("Édouard Manet", withTokenizer: .ascii()), ["Édouard", "manet"]) - try XCTAssertEqual(FTS5.tokenize("Édouard Manet", withTokenizer: .porter()), ["edouard", "manet"]) - try XCTAssertEqual(FTS5.tokenize("Édouard Manet", withTokenizer: .unicode61()), ["edouard", "manet"]) - try XCTAssertEqual(FTS5.tokenize("Édouard Manet", withTokenizer: .unicode61(diacritics: .keep)), ["édouard", "manet"]) - - // Prefix queries - try XCTAssertEqual(FTS5.tokenize("*"), []) - try XCTAssertEqual(FTS5.tokenize("*", withTokenizer: .ascii()), []) - try XCTAssertEqual(FTS5.tokenize("*", withTokenizer: .porter()), []) - try XCTAssertEqual(FTS5.tokenize("*", withTokenizer: .unicode61()), []) - try XCTAssertEqual(FTS5.tokenize("*", withTokenizer: .unicode61(diacritics: .keep)), []) - - try XCTAssertEqual(FTS5.tokenize("Robin*"), ["robin"]) - try XCTAssertEqual(FTS5.tokenize("Robin*", withTokenizer: .ascii()), ["robin"]) - try XCTAssertEqual(FTS5.tokenize("Robin*", withTokenizer: .porter()), ["robin"]) - try XCTAssertEqual(FTS5.tokenize("Robin*", withTokenizer: .unicode61()), ["robin"]) - try XCTAssertEqual(FTS5.tokenize("Robin*", withTokenizer: .unicode61(diacritics: .keep)), ["robin"]) - - // Phrase queries - try XCTAssertEqual(FTS5.tokenize("\"foulent muscles\""), ["foulent", "muscles"]) - try XCTAssertEqual(FTS5.tokenize("\"foulent muscles\"", withTokenizer: .ascii()), ["foulent", "muscles"]) - try XCTAssertEqual(FTS5.tokenize("\"foulent muscles\"", withTokenizer: .porter()), ["foulent", "muscl"]) - try XCTAssertEqual(FTS5.tokenize("\"foulent muscles\"", withTokenizer: .unicode61()), ["foulent", "muscles"]) - try XCTAssertEqual(FTS5.tokenize("\"foulent muscles\"", withTokenizer: .unicode61(diacritics: .keep)), ["foulent", "muscles"]) - - try XCTAssertEqual(FTS5.tokenize("\"Kim Stan* Robin*\""), ["kim", "stan", "robin"]) - try XCTAssertEqual(FTS5.tokenize("\"Kim Stan* Robin*\"", withTokenizer: .ascii()), ["kim", "stan", "robin"]) - try XCTAssertEqual(FTS5.tokenize("\"Kim Stan* Robin*\"", withTokenizer: .porter()), ["kim", "stan", "robin"]) - try XCTAssertEqual(FTS5.tokenize("\"Kim Stan* Robin*\"", withTokenizer: .unicode61()), ["kim", "stan", "robin"]) - try XCTAssertEqual(FTS5.tokenize("\"Kim Stan* Robin*\"", withTokenizer: .unicode61(diacritics: .keep)), ["kim", "stan", "robin"]) - - // Logical queries - try XCTAssertEqual(FTS5.tokenize("years AND months"), ["years", "and", "months"]) - try XCTAssertEqual(FTS5.tokenize("years AND months", withTokenizer: .ascii()), ["years", "and", "months"]) - try XCTAssertEqual(FTS5.tokenize("years AND months", withTokenizer: .porter()), ["year", "and", "month"]) - try XCTAssertEqual(FTS5.tokenize("years AND months", withTokenizer: .unicode61()), ["years", "and", "months"]) - try XCTAssertEqual(FTS5.tokenize("years AND months", withTokenizer: .unicode61(diacritics: .keep)), ["years", "and", "months"]) - - // column queries - try XCTAssertEqual(FTS5.tokenize("title:brest"), ["title", "brest"]) - try XCTAssertEqual(FTS5.tokenize("title:brest", withTokenizer: .ascii()), ["title", "brest"]) - try XCTAssertEqual(FTS5.tokenize("title:brest", withTokenizer: .porter()), ["titl", "brest"]) - try XCTAssertEqual(FTS5.tokenize("title:brest", withTokenizer: .unicode61()), ["title", "brest"]) - try XCTAssertEqual(FTS5.tokenize("title:brest", withTokenizer: .unicode61(diacritics: .keep)), ["title", "brest"]) - } - func testInvalidFTS5Pattern() throws { let dbQueue = try makeDatabaseQueue() dbQueue.inDatabase { db in diff --git a/Tests/GRDBTests/FTS5TokenizerTests.swift b/Tests/GRDBTests/FTS5TokenizerTests.swift index b2f292439..d3e0df7d6 100644 --- a/Tests/GRDBTests/FTS5TokenizerTests.swift +++ b/Tests/GRDBTests/FTS5TokenizerTests.swift @@ -225,5 +225,85 @@ class FTS5TokenizerTests: GRDBTestCase { XCTAssertFalse(match(db, "2016-10-04.txt", "txt")) } } + + func testTokenize() throws { + try makeDatabaseQueue().inDatabase { db in + let ascii = try db.makeTokenizer(.ascii()) + let porter = try db.makeTokenizer(.porter()) + let unicode61 = try db.makeTokenizer(.unicode61()) + let unicode61WithDiacritics = try db.makeTokenizer(.unicode61(diacritics: .keep)) + + // Empty query + try XCTAssertEqual(ascii.tokenize(query: "").map(\.token), []) + try XCTAssertEqual(porter.tokenize(query: "").map(\.token), []) + try XCTAssertEqual(unicode61.tokenize(query: "").map(\.token), []) + try XCTAssertEqual(unicode61WithDiacritics.tokenize(query: "").map(\.token), []) + + try XCTAssertEqual(ascii.tokenize(query: "?!").map(\.token), []) + try XCTAssertEqual(porter.tokenize(query: "?!").map(\.token), []) + try XCTAssertEqual(unicode61.tokenize(query: "?!").map(\.token), []) + try XCTAssertEqual(unicode61WithDiacritics.tokenize(query: "?!").map(\.token), []) + + // Token queries + try XCTAssertEqual(ascii.tokenize(query: "Moby").map(\.token), ["moby"]) + try XCTAssertEqual(porter.tokenize(query: "Moby").map(\.token), ["mobi"]) + try XCTAssertEqual(unicode61.tokenize(query: "Moby").map(\.token), ["moby"]) + try XCTAssertEqual(unicode61WithDiacritics.tokenize(query: "Moby").map(\.token), ["moby"]) + + try XCTAssertEqual(ascii.tokenize(query: "écarlates").map(\.token), ["écarlates"]) + try XCTAssertEqual(porter.tokenize(query: "écarlates").map(\.token), ["ecarl"]) + try XCTAssertEqual(unicode61.tokenize(query: "écarlates").map(\.token), ["ecarlates"]) + try XCTAssertEqual(unicode61WithDiacritics.tokenize(query: "écarlates").map(\.token), ["écarlates"]) + + try XCTAssertEqual(ascii.tokenize(query: "fooéı👨👨🏿🇫🇷🇨🇮").map(\.token), ["fooéı👨👨🏿🇫🇷🇨🇮"]) + try XCTAssertEqual(porter.tokenize(query: "fooéı👨👨🏿🇫🇷🇨🇮").map(\.token), ["fooeı", "🏿"]) // ¯\_(ツ)_/¯ + try XCTAssertEqual(unicode61.tokenize(query: "fooéı👨👨🏿🇫🇷🇨🇮").map(\.token), ["fooeı", "🏿"]) // ¯\_(ツ)_/¯ + try XCTAssertEqual(unicode61WithDiacritics.tokenize(query: "fooéı👨👨🏿🇫🇷🇨🇮").map(\.token), ["fooéı", "🏿"]) // ¯\_(ツ)_/¯ + + try XCTAssertEqual(ascii.tokenize(query: "SQLite database").map(\.token), ["sqlite", "database"]) + try XCTAssertEqual(porter.tokenize(query: "SQLite database").map(\.token), ["sqlite", "databas"]) + try XCTAssertEqual(unicode61.tokenize(query: "SQLite database").map(\.token), ["sqlite", "database"]) + try XCTAssertEqual(unicode61WithDiacritics.tokenize(query: "SQLite database").map(\.token), ["sqlite", "database"]) + + try XCTAssertEqual(ascii.tokenize(query: "Édouard Manet").map(\.token), ["Édouard", "manet"]) + try XCTAssertEqual(porter.tokenize(query: "Édouard Manet").map(\.token), ["edouard", "manet"]) + try XCTAssertEqual(unicode61.tokenize(query: "Édouard Manet").map(\.token), ["edouard", "manet"]) + try XCTAssertEqual(unicode61WithDiacritics.tokenize(query: "Édouard Manet").map(\.token), ["édouard", "manet"]) + + // Prefix queries + try XCTAssertEqual(ascii.tokenize(query: "*").map(\.token), []) + try XCTAssertEqual(porter.tokenize(query: "*").map(\.token), []) + try XCTAssertEqual(unicode61.tokenize(query: "*").map(\.token), []) + try XCTAssertEqual(unicode61WithDiacritics.tokenize(query: "*").map(\.token), []) + + try XCTAssertEqual(ascii.tokenize(query: "Robin*").map(\.token), ["robin"]) + try XCTAssertEqual(porter.tokenize(query: "Robin*").map(\.token), ["robin"]) + try XCTAssertEqual(unicode61.tokenize(query: "Robin*").map(\.token), ["robin"]) + try XCTAssertEqual(unicode61WithDiacritics.tokenize(query: "Robin*").map(\.token), ["robin"]) + + // Phrase queries + try XCTAssertEqual(ascii.tokenize(query: "\"foulent muscles\"").map(\.token), ["foulent", "muscles"]) + try XCTAssertEqual(porter.tokenize(query: "\"foulent muscles\"").map(\.token), ["foulent", "muscl"]) + try XCTAssertEqual(unicode61.tokenize(query: "\"foulent muscles\"").map(\.token), ["foulent", "muscles"]) + try XCTAssertEqual(unicode61WithDiacritics.tokenize(query: "\"foulent muscles\"").map(\.token), ["foulent", "muscles"]) + + try XCTAssertEqual(ascii.tokenize(query: "\"Kim Stan* Robin*\"").map(\.token), ["kim", "stan", "robin"]) + try XCTAssertEqual(porter.tokenize(query: "\"Kim Stan* Robin*\"").map(\.token), ["kim", "stan", "robin"]) + try XCTAssertEqual(unicode61.tokenize(query: "\"Kim Stan* Robin*\"").map(\.token), ["kim", "stan", "robin"]) + try XCTAssertEqual(unicode61WithDiacritics.tokenize(query: "\"Kim Stan* Robin*\"").map(\.token), ["kim", "stan", "robin"]) + + // Logical queries + try XCTAssertEqual(ascii.tokenize(query: "years AND months").map(\.token), ["years", "and", "months"]) + try XCTAssertEqual(porter.tokenize(query: "years AND months").map(\.token), ["year", "and", "month"]) + try XCTAssertEqual(unicode61.tokenize(query: "years AND months").map(\.token), ["years", "and", "months"]) + try XCTAssertEqual(unicode61WithDiacritics.tokenize(query: "years AND months").map(\.token), ["years", "and", "months"]) + + // column queries + try XCTAssertEqual(ascii.tokenize(query: "title:brest").map(\.token), ["title", "brest"]) + try XCTAssertEqual(porter.tokenize(query: "title:brest").map(\.token), ["titl", "brest"]) + try XCTAssertEqual(unicode61.tokenize(query: "title:brest").map(\.token), ["title", "brest"]) + try XCTAssertEqual(unicode61WithDiacritics.tokenize(query: "title:brest").map(\.token), ["title", "brest"]) + } + } } #endif From 79c5c1d1bad74dc118c4c9d0a2a7a3b49db35956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 25 Sep 2021 16:59:32 +0200 Subject: [PATCH 08/11] Failing test for #1059 Xcode 13, make test_install_SPM_ios_release --- Makefile | 28 +- Tests/SPM/ios/ios.xcodeproj/project.pbxproj | 385 ++++++++++ .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../xcshareddata/xcschemes/ios.xcscheme | 78 ++ Tests/SPM/ios/ios/AppDelegate.swift | 16 + .../AccentColor.colorset/Contents.json | 11 + .../AppIcon.appiconset/Contents.json | 98 +++ .../SPM/ios/ios/Assets.xcassets/Contents.json | 6 + .../ios/Base.lproj/LaunchScreen.storyboard | 25 + Tests/SPM/ios/ios/Base.lproj/Main.storyboard | 24 + Tests/SPM/ios/ios/Info.plist | 25 + Tests/SPM/ios/ios/SceneDelegate.swift | 5 + Tests/SPM/ios/ios/ViewController.swift | 3 + .../SPM/macos/macos.xcodeproj/project.pbxproj | 364 +++++++++ .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../xcshareddata/xcschemes/macos.xcscheme | 78 ++ Tests/SPM/macos/macos/AppDelegate.swift | 16 + .../AccentColor.colorset/Contents.json | 11 + .../AppIcon.appiconset/Contents.json | 58 ++ .../macos/macos/Assets.xcassets/Contents.json | 6 + .../macos/macos/Base.lproj/Main.storyboard | 717 ++++++++++++++++++ Tests/SPM/macos/macos/ViewController.swift | 3 + Tests/SPM/macos/macos/macos.entitlements | 10 + 25 files changed, 1995 insertions(+), 2 deletions(-) create mode 100644 Tests/SPM/ios/ios.xcodeproj/project.pbxproj create mode 100644 Tests/SPM/ios/ios.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 Tests/SPM/ios/ios.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 Tests/SPM/ios/ios.xcodeproj/xcshareddata/xcschemes/ios.xcscheme create mode 100644 Tests/SPM/ios/ios/AppDelegate.swift create mode 100644 Tests/SPM/ios/ios/Assets.xcassets/AccentColor.colorset/Contents.json create mode 100644 Tests/SPM/ios/ios/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 Tests/SPM/ios/ios/Assets.xcassets/Contents.json create mode 100644 Tests/SPM/ios/ios/Base.lproj/LaunchScreen.storyboard create mode 100644 Tests/SPM/ios/ios/Base.lproj/Main.storyboard create mode 100644 Tests/SPM/ios/ios/Info.plist create mode 100644 Tests/SPM/ios/ios/SceneDelegate.swift create mode 100644 Tests/SPM/ios/ios/ViewController.swift create mode 100644 Tests/SPM/macos/macos.xcodeproj/project.pbxproj create mode 100644 Tests/SPM/macos/macos.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 Tests/SPM/macos/macos.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 Tests/SPM/macos/macos.xcodeproj/xcshareddata/xcschemes/macos.xcscheme create mode 100644 Tests/SPM/macos/macos/AppDelegate.swift create mode 100644 Tests/SPM/macos/macos/Assets.xcassets/AccentColor.colorset/Contents.json create mode 100644 Tests/SPM/macos/macos/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 Tests/SPM/macos/macos/Assets.xcassets/Contents.json create mode 100644 Tests/SPM/macos/macos/Base.lproj/Main.storyboard create mode 100644 Tests/SPM/macos/macos/ViewController.swift create mode 100644 Tests/SPM/macos/macos/macos.entitlements diff --git a/Makefile b/Makefile index 5f695cb9f..c85acb60b 100644 --- a/Makefile +++ b/Makefile @@ -50,7 +50,14 @@ TEST_ACTIONS = clean build build-for-testing test-without-building # When adding support for an Xcode version, look for available devices with # `xcrun xctrace list devices` (or the deprecated `instruments -s devices`). -ifeq ($(XCODEVERSION),12.5) +ifeq ($(XCODEVERSION),13.0) + MAX_SWIFT_VERSION = 5.5 + MIN_SWIFT_VERSION = 5.2 + MAX_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 13,OS=15.0" + MIN_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 5s,OS=11.4" + MAX_TVOS_DESTINATION = "platform=tvOS Simulator,name=Apple TV,OS=15.0" + MIN_TVOS_DESTINATION = "platform=tvOS Simulator,name=Apple TV,OS=11.4" +else ifeq ($(XCODEVERSION),12.5) MAX_SWIFT_VERSION = 5.4 MIN_SWIFT_VERSION = 5.2 MAX_IOS_DESTINATION = "platform=iOS Simulator,name=iPhone 12,OS=14.5" @@ -341,7 +348,7 @@ test_install_manual: clean build \ $(XCPRETTY) -test_install_SPM: test_install_SPM_Package test_install_SPM_Project +test_install_SPM: test_install_SPM_Package test_install_SPM_Project test_install_SPM_macos_release test_install_SPM_ios_release test_install_SPM_Package: cd Tests/SPM/PlainPackage && \ @@ -356,6 +363,23 @@ test_install_SPM_Project: clean build \ $(XCPRETTY) +test_install_SPM_macos_release: + $(XCODEBUILD) \ + -project Tests/SPM/macos/macos.xcodeproj \ + -scheme macos \ + -configuration Release \ + clean build \ + $(XCPRETTY) + +test_install_SPM_ios_release: + $(XCODEBUILD) \ + -project Tests/SPM/ios/ios.xcodeproj \ + -scheme ios \ + -destination $(MAX_IOS_DESTINATION) \ + -configuration Release \ + clean build \ + $(XCPRETTY) + test_install_customSQLite: SQLiteCustom $(XCODEBUILD) \ -project Tests/CustomSQLite/CustomSQLite.xcodeproj \ diff --git a/Tests/SPM/ios/ios.xcodeproj/project.pbxproj b/Tests/SPM/ios/ios.xcodeproj/project.pbxproj new file mode 100644 index 000000000..8572075af --- /dev/null +++ b/Tests/SPM/ios/ios.xcodeproj/project.pbxproj @@ -0,0 +1,385 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 55; + objects = { + +/* Begin PBXBuildFile section */ + 5667C2B626FF6ADE00FD996F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5667C2B526FF6ADE00FD996F /* AppDelegate.swift */; }; + 5667C2B826FF6ADE00FD996F /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5667C2B726FF6ADE00FD996F /* SceneDelegate.swift */; }; + 5667C2BA26FF6ADE00FD996F /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5667C2B926FF6ADE00FD996F /* ViewController.swift */; }; + 5667C2BD26FF6ADE00FD996F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5667C2BB26FF6ADE00FD996F /* Main.storyboard */; }; + 5667C2BF26FF6AE100FD996F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5667C2BE26FF6AE100FD996F /* Assets.xcassets */; }; + 5667C2C226FF6AE100FD996F /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5667C2C026FF6AE100FD996F /* LaunchScreen.storyboard */; }; + 5667C2CC26FF6B8B00FD996F /* GRDB in Frameworks */ = {isa = PBXBuildFile; productRef = 5667C2CB26FF6B8B00FD996F /* GRDB */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 5667C2B226FF6ADE00FD996F /* ios.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ios.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 5667C2B526FF6ADE00FD996F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 5667C2B726FF6ADE00FD996F /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; + 5667C2B926FF6ADE00FD996F /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + 5667C2BC26FF6ADE00FD996F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 5667C2BE26FF6AE100FD996F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 5667C2C126FF6AE100FD996F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 5667C2C326FF6AE100FD996F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 5667C2C926FF6AE800FD996F /* GRDB.swift */ = {isa = PBXFileReference; lastKnownFileType = folder; name = GRDB.swift; path = ../../..; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 5667C2AF26FF6ADE00FD996F /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 5667C2CC26FF6B8B00FD996F /* GRDB in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 5667C2A926FF6ADE00FD996F = { + isa = PBXGroup; + children = ( + 5667C2B426FF6ADE00FD996F /* ios */, + 5667C2C926FF6AE800FD996F /* GRDB.swift */, + 5667C2B326FF6ADE00FD996F /* Products */, + 5667C2CA26FF6B8B00FD996F /* Frameworks */, + ); + sourceTree = ""; + }; + 5667C2B326FF6ADE00FD996F /* Products */ = { + isa = PBXGroup; + children = ( + 5667C2B226FF6ADE00FD996F /* ios.app */, + ); + name = Products; + sourceTree = ""; + }; + 5667C2B426FF6ADE00FD996F /* ios */ = { + isa = PBXGroup; + children = ( + 5667C2B526FF6ADE00FD996F /* AppDelegate.swift */, + 5667C2B726FF6ADE00FD996F /* SceneDelegate.swift */, + 5667C2B926FF6ADE00FD996F /* ViewController.swift */, + 5667C2BB26FF6ADE00FD996F /* Main.storyboard */, + 5667C2BE26FF6AE100FD996F /* Assets.xcassets */, + 5667C2C026FF6AE100FD996F /* LaunchScreen.storyboard */, + 5667C2C326FF6AE100FD996F /* Info.plist */, + ); + path = ios; + sourceTree = ""; + }; + 5667C2CA26FF6B8B00FD996F /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 5667C2B126FF6ADE00FD996F /* ios */ = { + isa = PBXNativeTarget; + buildConfigurationList = 5667C2C626FF6AE100FD996F /* Build configuration list for PBXNativeTarget "ios" */; + buildPhases = ( + 5667C2AE26FF6ADE00FD996F /* Sources */, + 5667C2AF26FF6ADE00FD996F /* Frameworks */, + 5667C2B026FF6ADE00FD996F /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = ios; + packageProductDependencies = ( + 5667C2CB26FF6B8B00FD996F /* GRDB */, + ); + productName = ios; + productReference = 5667C2B226FF6ADE00FD996F /* ios.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 5667C2AA26FF6ADE00FD996F /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1300; + LastUpgradeCheck = 1300; + TargetAttributes = { + 5667C2B126FF6ADE00FD996F = { + CreatedOnToolsVersion = 13.0; + }; + }; + }; + buildConfigurationList = 5667C2AD26FF6ADE00FD996F /* Build configuration list for PBXProject "ios" */; + compatibilityVersion = "Xcode 13.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 5667C2A926FF6ADE00FD996F; + productRefGroup = 5667C2B326FF6ADE00FD996F /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 5667C2B126FF6ADE00FD996F /* ios */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 5667C2B026FF6ADE00FD996F /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 5667C2C226FF6AE100FD996F /* LaunchScreen.storyboard in Resources */, + 5667C2BF26FF6AE100FD996F /* Assets.xcassets in Resources */, + 5667C2BD26FF6ADE00FD996F /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 5667C2AE26FF6ADE00FD996F /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 5667C2BA26FF6ADE00FD996F /* ViewController.swift in Sources */, + 5667C2B626FF6ADE00FD996F /* AppDelegate.swift in Sources */, + 5667C2B826FF6ADE00FD996F /* SceneDelegate.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 5667C2BB26FF6ADE00FD996F /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 5667C2BC26FF6ADE00FD996F /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 5667C2C026FF6AE100FD996F /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 5667C2C126FF6AE100FD996F /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 5667C2C426FF6AE100FD996F /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 15.0; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 5667C2C526FF6AE100FD996F /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 15.0; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 5667C2C726FF6AE100FD996F /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = ios/Info.plist; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; + INFOPLIST_KEY_UIMainStoryboardFile = Main; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.ios; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 5667C2C826FF6AE100FD996F /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = ios/Info.plist; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen; + INFOPLIST_KEY_UIMainStoryboardFile = Main; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.ios; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 5667C2AD26FF6ADE00FD996F /* Build configuration list for PBXProject "ios" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 5667C2C426FF6AE100FD996F /* Debug */, + 5667C2C526FF6AE100FD996F /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 5667C2C626FF6AE100FD996F /* Build configuration list for PBXNativeTarget "ios" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 5667C2C726FF6AE100FD996F /* Debug */, + 5667C2C826FF6AE100FD996F /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + +/* Begin XCSwiftPackageProductDependency section */ + 5667C2CB26FF6B8B00FD996F /* GRDB */ = { + isa = XCSwiftPackageProductDependency; + productName = GRDB; + }; +/* End XCSwiftPackageProductDependency section */ + }; + rootObject = 5667C2AA26FF6ADE00FD996F /* Project object */; +} diff --git a/Tests/SPM/ios/ios.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Tests/SPM/ios/ios.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 000000000..919434a62 --- /dev/null +++ b/Tests/SPM/ios/ios.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Tests/SPM/ios/ios.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Tests/SPM/ios/ios.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Tests/SPM/ios/ios.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Tests/SPM/ios/ios.xcodeproj/xcshareddata/xcschemes/ios.xcscheme b/Tests/SPM/ios/ios.xcodeproj/xcshareddata/xcschemes/ios.xcscheme new file mode 100644 index 000000000..85c8fb1fb --- /dev/null +++ b/Tests/SPM/ios/ios.xcodeproj/xcshareddata/xcschemes/ios.xcscheme @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/SPM/ios/ios/AppDelegate.swift b/Tests/SPM/ios/ios/AppDelegate.swift new file mode 100644 index 000000000..e6f48b344 --- /dev/null +++ b/Tests/SPM/ios/ios/AppDelegate.swift @@ -0,0 +1,16 @@ +import UIKit +import GRDB + +@main +class AppDelegate: UIResponder, UIApplicationDelegate { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + _ = DatabaseQueue() + .readPublisher(value: { _ in }) + .assertNoFailure() + return true + } + + func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { + return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) + } +} diff --git a/Tests/SPM/ios/ios/Assets.xcassets/AccentColor.colorset/Contents.json b/Tests/SPM/ios/ios/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 000000000..eb8789700 --- /dev/null +++ b/Tests/SPM/ios/ios/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Tests/SPM/ios/ios/Assets.xcassets/AppIcon.appiconset/Contents.json b/Tests/SPM/ios/ios/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 000000000..9221b9bb1 --- /dev/null +++ b/Tests/SPM/ios/ios/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,98 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "20x20" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "20x20" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "29x29" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "29x29" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "40x40" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "40x40" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "60x60" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "60x60" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "20x20" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "20x20" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "29x29" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "29x29" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "40x40" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "40x40" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "76x76" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "76x76" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "83.5x83.5" + }, + { + "idiom" : "ios-marketing", + "scale" : "1x", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Tests/SPM/ios/ios/Assets.xcassets/Contents.json b/Tests/SPM/ios/ios/Assets.xcassets/Contents.json new file mode 100644 index 000000000..73c00596a --- /dev/null +++ b/Tests/SPM/ios/ios/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Tests/SPM/ios/ios/Base.lproj/LaunchScreen.storyboard b/Tests/SPM/ios/ios/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 000000000..865e9329f --- /dev/null +++ b/Tests/SPM/ios/ios/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/SPM/ios/ios/Base.lproj/Main.storyboard b/Tests/SPM/ios/ios/Base.lproj/Main.storyboard new file mode 100644 index 000000000..25a763858 --- /dev/null +++ b/Tests/SPM/ios/ios/Base.lproj/Main.storyboard @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/SPM/ios/ios/Info.plist b/Tests/SPM/ios/ios/Info.plist new file mode 100644 index 000000000..dd3c9afda --- /dev/null +++ b/Tests/SPM/ios/ios/Info.plist @@ -0,0 +1,25 @@ + + + + + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + $(PRODUCT_MODULE_NAME).SceneDelegate + UISceneStoryboardFile + Main + + + + + + diff --git a/Tests/SPM/ios/ios/SceneDelegate.swift b/Tests/SPM/ios/ios/SceneDelegate.swift new file mode 100644 index 000000000..e0be6e9cf --- /dev/null +++ b/Tests/SPM/ios/ios/SceneDelegate.swift @@ -0,0 +1,5 @@ +import UIKit + +class SceneDelegate: UIResponder, UIWindowSceneDelegate { + var window: UIWindow? +} diff --git a/Tests/SPM/ios/ios/ViewController.swift b/Tests/SPM/ios/ios/ViewController.swift new file mode 100644 index 000000000..0557bbbcf --- /dev/null +++ b/Tests/SPM/ios/ios/ViewController.swift @@ -0,0 +1,3 @@ +import UIKit + +class ViewController: UIViewController { } diff --git a/Tests/SPM/macos/macos.xcodeproj/project.pbxproj b/Tests/SPM/macos/macos.xcodeproj/project.pbxproj new file mode 100644 index 000000000..1a8029d98 --- /dev/null +++ b/Tests/SPM/macos/macos.xcodeproj/project.pbxproj @@ -0,0 +1,364 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 55; + objects = { + +/* Begin PBXBuildFile section */ + 5667C29726FF69BD00FD996F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5667C29626FF69BD00FD996F /* AppDelegate.swift */; }; + 5667C29926FF69BD00FD996F /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5667C29826FF69BD00FD996F /* ViewController.swift */; }; + 5667C29B26FF69C000FD996F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5667C29A26FF69C000FD996F /* Assets.xcassets */; }; + 5667C29E26FF69C000FD996F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5667C29C26FF69C000FD996F /* Main.storyboard */; }; + 5667C2A826FF6A3100FD996F /* GRDB in Frameworks */ = {isa = PBXBuildFile; productRef = 5667C2A726FF6A3100FD996F /* GRDB */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 5667C29326FF69BD00FD996F /* macos.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = macos.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 5667C29626FF69BD00FD996F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 5667C29826FF69BD00FD996F /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; + 5667C29A26FF69C000FD996F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 5667C29D26FF69C000FD996F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 5667C29F26FF69C000FD996F /* macos.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = macos.entitlements; sourceTree = ""; }; + 5667C2A526FF69D500FD996F /* GRDB.swift */ = {isa = PBXFileReference; lastKnownFileType = folder; name = GRDB.swift; path = ../../..; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 5667C29026FF69BD00FD996F /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 5667C2A826FF6A3100FD996F /* GRDB in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 5667C28A26FF69BD00FD996F = { + isa = PBXGroup; + children = ( + 5667C29526FF69BD00FD996F /* macos */, + 5667C2A526FF69D500FD996F /* GRDB.swift */, + 5667C29426FF69BD00FD996F /* Products */, + 5667C2A626FF6A3100FD996F /* Frameworks */, + ); + sourceTree = ""; + }; + 5667C29426FF69BD00FD996F /* Products */ = { + isa = PBXGroup; + children = ( + 5667C29326FF69BD00FD996F /* macos.app */, + ); + name = Products; + sourceTree = ""; + }; + 5667C29526FF69BD00FD996F /* macos */ = { + isa = PBXGroup; + children = ( + 5667C29626FF69BD00FD996F /* AppDelegate.swift */, + 5667C29826FF69BD00FD996F /* ViewController.swift */, + 5667C29A26FF69C000FD996F /* Assets.xcassets */, + 5667C29C26FF69C000FD996F /* Main.storyboard */, + 5667C29F26FF69C000FD996F /* macos.entitlements */, + ); + path = macos; + sourceTree = ""; + }; + 5667C2A626FF6A3100FD996F /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 5667C29226FF69BD00FD996F /* macos */ = { + isa = PBXNativeTarget; + buildConfigurationList = 5667C2A226FF69C000FD996F /* Build configuration list for PBXNativeTarget "macos" */; + buildPhases = ( + 5667C28F26FF69BD00FD996F /* Sources */, + 5667C29026FF69BD00FD996F /* Frameworks */, + 5667C29126FF69BD00FD996F /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = macos; + packageProductDependencies = ( + 5667C2A726FF6A3100FD996F /* GRDB */, + ); + productName = macos; + productReference = 5667C29326FF69BD00FD996F /* macos.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 5667C28B26FF69BD00FD996F /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1300; + LastUpgradeCheck = 1300; + TargetAttributes = { + 5667C29226FF69BD00FD996F = { + CreatedOnToolsVersion = 13.0; + }; + }; + }; + buildConfigurationList = 5667C28E26FF69BD00FD996F /* Build configuration list for PBXProject "macos" */; + compatibilityVersion = "Xcode 13.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 5667C28A26FF69BD00FD996F; + productRefGroup = 5667C29426FF69BD00FD996F /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 5667C29226FF69BD00FD996F /* macos */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 5667C29126FF69BD00FD996F /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 5667C29B26FF69C000FD996F /* Assets.xcassets in Resources */, + 5667C29E26FF69C000FD996F /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 5667C28F26FF69BD00FD996F /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 5667C29926FF69BD00FD996F /* ViewController.swift in Sources */, + 5667C29726FF69BD00FD996F /* AppDelegate.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 5667C29C26FF69C000FD996F /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 5667C29D26FF69C000FD996F /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 5667C2A026FF69C000FD996F /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 11.3; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 5667C2A126FF69C000FD996F /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 11.3; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + 5667C2A326FF69C000FD996F /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = macos/macos.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_NSHumanReadableCopyright = ""; + INFOPLIST_KEY_NSMainStoryboardFile = Main; + INFOPLIST_KEY_NSPrincipalClass = NSApplication; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.macos; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 5667C2A426FF69C000FD996F /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = macos/macos.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_NSHumanReadableCopyright = ""; + INFOPLIST_KEY_NSMainStoryboardFile = Main; + INFOPLIST_KEY_NSPrincipalClass = NSApplication; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.macos; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 5667C28E26FF69BD00FD996F /* Build configuration list for PBXProject "macos" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 5667C2A026FF69C000FD996F /* Debug */, + 5667C2A126FF69C000FD996F /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 5667C2A226FF69C000FD996F /* Build configuration list for PBXNativeTarget "macos" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 5667C2A326FF69C000FD996F /* Debug */, + 5667C2A426FF69C000FD996F /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + +/* Begin XCSwiftPackageProductDependency section */ + 5667C2A726FF6A3100FD996F /* GRDB */ = { + isa = XCSwiftPackageProductDependency; + productName = GRDB; + }; +/* End XCSwiftPackageProductDependency section */ + }; + rootObject = 5667C28B26FF69BD00FD996F /* Project object */; +} diff --git a/Tests/SPM/macos/macos.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Tests/SPM/macos/macos.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 000000000..919434a62 --- /dev/null +++ b/Tests/SPM/macos/macos.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Tests/SPM/macos/macos.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Tests/SPM/macos/macos.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/Tests/SPM/macos/macos.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Tests/SPM/macos/macos.xcodeproj/xcshareddata/xcschemes/macos.xcscheme b/Tests/SPM/macos/macos.xcodeproj/xcshareddata/xcschemes/macos.xcscheme new file mode 100644 index 000000000..9e736e475 --- /dev/null +++ b/Tests/SPM/macos/macos.xcodeproj/xcshareddata/xcschemes/macos.xcscheme @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/SPM/macos/macos/AppDelegate.swift b/Tests/SPM/macos/macos/AppDelegate.swift new file mode 100644 index 000000000..11cb5cdcc --- /dev/null +++ b/Tests/SPM/macos/macos/AppDelegate.swift @@ -0,0 +1,16 @@ +import Cocoa +import GRDB + +@main +class AppDelegate: NSObject, NSApplicationDelegate { + func applicationDidFinishLaunching(_ aNotification: Notification) { + _ = DatabaseQueue() + } + + func applicationWillTerminate(_ aNotification: Notification) { + } + + func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool { + return true + } +} diff --git a/Tests/SPM/macos/macos/Assets.xcassets/AccentColor.colorset/Contents.json b/Tests/SPM/macos/macos/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 000000000..eb8789700 --- /dev/null +++ b/Tests/SPM/macos/macos/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Tests/SPM/macos/macos/Assets.xcassets/AppIcon.appiconset/Contents.json b/Tests/SPM/macos/macos/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 000000000..3f00db43e --- /dev/null +++ b/Tests/SPM/macos/macos/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,58 @@ +{ + "images" : [ + { + "idiom" : "mac", + "scale" : "1x", + "size" : "16x16" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "16x16" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "32x32" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "32x32" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "128x128" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "128x128" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "256x256" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "256x256" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "512x512" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "512x512" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Tests/SPM/macos/macos/Assets.xcassets/Contents.json b/Tests/SPM/macos/macos/Assets.xcassets/Contents.json new file mode 100644 index 000000000..73c00596a --- /dev/null +++ b/Tests/SPM/macos/macos/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Tests/SPM/macos/macos/Base.lproj/Main.storyboard b/Tests/SPM/macos/macos/Base.lproj/Main.storyboard new file mode 100644 index 000000000..1986cd816 --- /dev/null +++ b/Tests/SPM/macos/macos/Base.lproj/Main.storyboard @@ -0,0 +1,717 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Default + + + + + + + Left to Right + + + + + + + Right to Left + + + + + + + + + + + Default + + + + + + + Left to Right + + + + + + + Right to Left + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/SPM/macos/macos/ViewController.swift b/Tests/SPM/macos/macos/ViewController.swift new file mode 100644 index 000000000..d44c61bd1 --- /dev/null +++ b/Tests/SPM/macos/macos/ViewController.swift @@ -0,0 +1,3 @@ +import Cocoa + +class ViewController: NSViewController { } diff --git a/Tests/SPM/macos/macos/macos.entitlements b/Tests/SPM/macos/macos/macos.entitlements new file mode 100644 index 000000000..f2ef3ae02 --- /dev/null +++ b/Tests/SPM/macos/macos/macos.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.files.user-selected.read-only + + + From 6724862eea529e2aa292fade753f6a0dcd6f2cbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 25 Sep 2021 17:02:27 +0200 Subject: [PATCH 09/11] Bump min iOS version to 11.0 This drops support for 32 bit devices Fix #1059 Fix #1033 --- Documentation/GRDB5MigrationGuide.md | 2 +- GRDB.swift.podspec | 2 +- Package.swift | 8 ++++---- README.md | 2 +- SQLiteCustom/GRDBDeploymentTarget.xcconfig | 2 +- Support/GRDBDeploymentTarget.xcconfig | 2 +- Tests/CocoaPods/GRDBiOS-framework/Podfile | 2 +- .../GRDBiOS-framework/iOS.xcodeproj/project.pbxproj | 10 ++++++---- Tests/CocoaPods/GRDBiOS-static/Podfile | 2 +- .../GRDBiOS-static/iOS.xcodeproj/project.pbxproj | 4 ++-- 10 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Documentation/GRDB5MigrationGuide.md b/Documentation/GRDB5MigrationGuide.md index 4bf4584e4..b83fbb465 100644 --- a/Documentation/GRDB5MigrationGuide.md +++ b/Documentation/GRDB5MigrationGuide.md @@ -26,7 +26,7 @@ GRDB requirements have been bumped: - **Swift 5.2+** (was Swift 4.2+) - **Xcode 11.4+** (was Xcode 10.0+) -- **iOS 10.0+** (was iOS 9.0+) +- **iOS 11.0+** (was iOS 9.0+) - **macOS 10.10+** (was macOS 10.9+) - tvOS 9.0+ (unchanged) - watchOS 2.0+ (unchanged) diff --git a/GRDB.swift.podspec b/GRDB.swift.podspec index c37b6bf58..10c042ad6 100644 --- a/GRDB.swift.podspec +++ b/GRDB.swift.podspec @@ -10,7 +10,7 @@ Pod::Spec.new do |s| s.module_name = 'GRDB' s.swift_versions = ['5.2'] - s.ios.deployment_target = '10.0' + s.ios.deployment_target = '11.0' s.osx.deployment_target = '10.10' s.watchos.deployment_target = '2.0' s.tvos.deployment_target = '9.0' diff --git a/Package.swift b/Package.swift index 940e4d848..ae25dea41 100644 --- a/Package.swift +++ b/Package.swift @@ -6,10 +6,10 @@ import PackageDescription let package = Package( name: "GRDB", platforms: [ - .iOS("10.0"), - .macOS("10.10"), - .tvOS("9.0"), - .watchOS("2.0"), + .iOS(.v11), + .macOS(.v10_10), + .tvOS(.v9), + .watchOS(.v2), ], products: [ .library(name: "GRDB", targets: ["GRDB"]), diff --git a/README.md b/README.md index 725ae838b..8f4a50c21 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ **Latest release**: September 3, 2021 • version 5.11.0 • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 4 to GRDB 5](Documentation/GRDB5MigrationGuide.md) -**Requirements**: iOS 10.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+ • SQLite 3.8.5+ • Swift 5.2+ / Xcode 11.4+ +**Requirements**: iOS 11.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+ • SQLite 3.8.5+ • Swift 5.2+ / Xcode 11.4+ | Swift version | GRDB version | | -------------- | ----------------------------------------------------------- | diff --git a/SQLiteCustom/GRDBDeploymentTarget.xcconfig b/SQLiteCustom/GRDBDeploymentTarget.xcconfig index 58994c0a3..28b7b90cc 100644 --- a/SQLiteCustom/GRDBDeploymentTarget.xcconfig +++ b/SQLiteCustom/GRDBDeploymentTarget.xcconfig @@ -1,4 +1,4 @@ -IPHONEOS_DEPLOYMENT_TARGET = 10.0 +IPHONEOS_DEPLOYMENT_TARGET = 11.0 MACOSX_DEPLOYMENT_TARGET = 10.10 TVOS_DEPLOYMENT_TARGET = 9.0 WATCHOS_DEPLOYMENT_TARGET = 2.0 diff --git a/Support/GRDBDeploymentTarget.xcconfig b/Support/GRDBDeploymentTarget.xcconfig index a88f9e56d..a7396f751 100644 --- a/Support/GRDBDeploymentTarget.xcconfig +++ b/Support/GRDBDeploymentTarget.xcconfig @@ -1,4 +1,4 @@ -IPHONEOS_DEPLOYMENT_TARGET = 10.0 +IPHONEOS_DEPLOYMENT_TARGET = 11.0 MACOSX_DEPLOYMENT_TARGET = 10.10 TVOS_DEPLOYMENT_TARGET = 9.0 WATCHOS_DEPLOYMENT_TARGET = 2.0 diff --git a/Tests/CocoaPods/GRDBiOS-framework/Podfile b/Tests/CocoaPods/GRDBiOS-framework/Podfile index ea7d91e6c..098cd8168 100644 --- a/Tests/CocoaPods/GRDBiOS-framework/Podfile +++ b/Tests/CocoaPods/GRDBiOS-framework/Podfile @@ -1,6 +1,6 @@ use_frameworks! target 'iOS' -platform :ios, '10.0' +platform :ios, '11.0' pod 'GRDB.swift', :path => '../../..' post_install do |installer| diff --git a/Tests/CocoaPods/GRDBiOS-framework/iOS.xcodeproj/project.pbxproj b/Tests/CocoaPods/GRDBiOS-framework/iOS.xcodeproj/project.pbxproj index a619c60fa..4de5afc20 100644 --- a/Tests/CocoaPods/GRDBiOS-framework/iOS.xcodeproj/project.pbxproj +++ b/Tests/CocoaPods/GRDBiOS-framework/iOS.xcodeproj/project.pbxproj @@ -96,7 +96,7 @@ 567374351B4D46600089DE44 /* Frameworks */, 567374361B4D46600089DE44 /* Resources */, 5644E4071C1072CA0090716E /* Embed Frameworks */, - 42992B3BE6585CF939B0D8EF /* [CP] Embed Pods Frameworks */, + 846C75E920926E1E5C32A97F /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -154,7 +154,7 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 42992B3BE6585CF939B0D8EF /* [CP] Embed Pods Frameworks */ = { + 846C75E920926E1E5C32A97F /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -251,7 +251,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -301,7 +301,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_COMPILATION_MODE = wholemodule; @@ -318,6 +318,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; INFOPLIST_FILE = Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBTest; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -334,6 +335,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; INFOPLIST_FILE = Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBTest; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/Tests/CocoaPods/GRDBiOS-static/Podfile b/Tests/CocoaPods/GRDBiOS-static/Podfile index 882142de1..351d37564 100644 --- a/Tests/CocoaPods/GRDBiOS-static/Podfile +++ b/Tests/CocoaPods/GRDBiOS-static/Podfile @@ -1,5 +1,5 @@ target 'iOS' -platform :ios, '10.0' +platform :ios, '11.0' pod 'GRDB.swift', :path => '../../..' post_install do |installer| diff --git a/Tests/CocoaPods/GRDBiOS-static/iOS.xcodeproj/project.pbxproj b/Tests/CocoaPods/GRDBiOS-static/iOS.xcodeproj/project.pbxproj index a9994316e..625554512 100644 --- a/Tests/CocoaPods/GRDBiOS-static/iOS.xcodeproj/project.pbxproj +++ b/Tests/CocoaPods/GRDBiOS-static/iOS.xcodeproj/project.pbxproj @@ -232,7 +232,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -282,7 +282,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 10.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_COMPILATION_MODE = wholemodule; From abcbf72421c6493bfe9dbe94fe822c6527fb70dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 25 Sep 2021 17:37:11 +0200 Subject: [PATCH 10/11] CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dbab1fa3..047ad516e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,6 +80,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: ## Unreleased +- **Breaking Change**: Minimum iOS version is now iOS 11.0, and 32-bits devices are no longer supported. This fixes issues introduced by Xcode 13 ([#1033](https://github.com/groue/GRDB.swift/issues/1033), [#1059](https://github.com/groue/GRDB.swift/issues/1059)). - **New**: `FTS3Pattern(matchingAllPrefixesIn:)` and `FTS5Pattern(matchingAllPrefixesIn:)` let you build full-text search patterns suitable for prefix queries. - **New**: `FTS3.tokenize(_:)` and `FTS5Tokenizer.tokenize(_:)` let you tokenize input strings. - **Documentation Update**: Full-text search documentation was updated for the new search pattern initializers ([FTS3/4](Documentation/FullTextSearch.md#fts3pattern), [FTS5](Documentation/FullTextSearch.md#fts5pattern)), and tokenization methods ([FTS3/4](Documentation/FullTextSearch.md#fts3-and-fts4-tokenization), [FTS5](Documentation/FullTextSearch.md#fts5-tokenization)). From dbb4668033a4bf7b4a5c0490fb81a1237cc03d5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 25 Sep 2021 17:41:41 +0200 Subject: [PATCH 11/11] v5.12.0 --- CHANGELOG.md | 5 +++- Documentation/FullTextSearch.md | 4 +-- Documentation/Migrations.md | 2 +- GRDB.swift.podspec | 2 +- Makefile | 6 ++--- README.md | 44 ++++++++++++++++----------------- Support/Info.plist | 2 +- 7 files changed, 34 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 047ad516e..7c9515d2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: #### 5.x Releases +- `5.12.x` Releases - [5.12.0](#5120) - `5.11.x` Releases - [5.11.0](#5110) - `5.10.x` Releases - [5.10.0](#5100) - `5.9.x` Releases - [5.9.0](#590) @@ -78,7 +79,9 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: --- -## Unreleased +## 5.12.0 + +Released September 25, 2021 • [diff](https://github.com/groue/GRDB.swift/compare/v5.11.0...v5.12.0) - **Breaking Change**: Minimum iOS version is now iOS 11.0, and 32-bits devices are no longer supported. This fixes issues introduced by Xcode 13 ([#1033](https://github.com/groue/GRDB.swift/issues/1033), [#1059](https://github.com/groue/GRDB.swift/issues/1059)). - **New**: `FTS3Pattern(matchingAllPrefixesIn:)` and `FTS5Pattern(matchingAllPrefixesIn:)` let you build full-text search patterns suitable for prefix queries. diff --git a/Documentation/FullTextSearch.md b/Documentation/FullTextSearch.md index 0bf70a2b6..9233f4ed7 100644 --- a/Documentation/FullTextSearch.md +++ b/Documentation/FullTextSearch.md @@ -304,7 +304,7 @@ let pattern = FTS3Pattern(matchingAnyTokenIn: "") // nil let pattern = FTS3Pattern(matchingAnyTokenIn: "*") // nil ``` -FTS3Pattern are regular [values](../README.md#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/5.11/Structs/StatementArguments.html): +FTS3Pattern are regular [values](../README.md#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/5.12/Structs/StatementArguments.html): ```swift let documents = try Document.fetchAll(db, @@ -587,7 +587,7 @@ let pattern = FTS5Pattern(matchingAnyTokenIn: "") // nil let pattern = FTS5Pattern(matchingAnyTokenIn: "*") // nil ``` -FTS5Pattern are regular [values](../README.md#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/5.11/Structs/StatementArguments.html): +FTS5Pattern are regular [values](../README.md#values). You can use them as query [arguments](http://groue.github.io/GRDB.swift/docs/5.12/Structs/StatementArguments.html): ```swift let documents = try Document.fetchAll(db, diff --git a/Documentation/Migrations.md b/Documentation/Migrations.md index 6b31d5f5c..aca5bf756 100644 --- a/Documentation/Migrations.md +++ b/Documentation/Migrations.md @@ -68,7 +68,7 @@ try dbQueue.read { db in } ``` -See the [DatabaseMigrator reference](http://groue.github.io/GRDB.swift/docs/5.11/Structs/DatabaseMigrator.html) for more migrator methods. +See the [DatabaseMigrator reference](http://groue.github.io/GRDB.swift/docs/5.12/Structs/DatabaseMigrator.html) for more migrator methods. ## The `eraseDatabaseOnSchemaChange` Option diff --git a/GRDB.swift.podspec b/GRDB.swift.podspec index 10c042ad6..a80cc66c8 100644 --- a/GRDB.swift.podspec +++ b/GRDB.swift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'GRDB.swift' - s.version = '5.11.0' + s.version = '5.12.0' s.license = { :type => 'MIT', :file => 'LICENSE' } s.summary = 'A toolkit for SQLite databases, with a focus on application development.' diff --git a/Makefile b/Makefile index c85acb60b..2aecaa3ac 100644 --- a/Makefile +++ b/Makefile @@ -462,10 +462,10 @@ ifdef JAZZY --author 'Gwendal Roué' \ --author_url https://github.com/groue \ --github_url https://github.com/groue/GRDB.swift \ - --github-file-prefix https://github.com/groue/GRDB.swift/tree/v5.11.0 \ - --module-version 5.11.0 \ + --github-file-prefix https://github.com/groue/GRDB.swift/tree/v5.12.0 \ + --module-version 5.12.0 \ --module GRDB \ - --root-url http://groue.github.io/GRDB.swift/docs/5.11/ \ + --root-url http://groue.github.io/GRDB.swift/docs/5.12/ \ --output Documentation/Reference \ --xcodebuild-arguments -project,GRDB.xcodeproj,-scheme,GRDBiOS else diff --git a/README.md b/README.md index 8f4a50c21..5af35dacf 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,13 @@ --- -**Latest release**: September 3, 2021 • version 5.11.0 • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 4 to GRDB 5](Documentation/GRDB5MigrationGuide.md) +**Latest release**: September 25, 2021 • version 5.12.0 • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 4 to GRDB 5](Documentation/GRDB5MigrationGuide.md) **Requirements**: iOS 11.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+ • SQLite 3.8.5+ • Swift 5.2+ / Xcode 11.4+ | Swift version | GRDB version | | -------------- | ----------------------------------------------------------- | -| **Swift 5.2+** | **v5.11.0** | +| **Swift 5.2+** | **v5.12.0** | | Swift 5.1 | [v4.14.0](https://github.com/groue/GRDB.swift/tree/v4.14.0) | | Swift 5 | [v4.14.0](https://github.com/groue/GRDB.swift/tree/v4.14.0) | | Swift 4.2 | [v4.14.0](https://github.com/groue/GRDB.swift/tree/v4.14.0) | @@ -316,7 +316,7 @@ Documentation #### Reference -- [GRDB Reference](http://groue.github.io/GRDB.swift/docs/5.11/index.html) (generated by [Jazzy](https://github.com/realm/jazzy)) +- [GRDB Reference](http://groue.github.io/GRDB.swift/docs/5.12/index.html) (generated by [Jazzy](https://github.com/realm/jazzy)) #### Getting Started @@ -510,7 +510,7 @@ let dbQueue = try DatabaseQueue( configuration: config) ``` -See [Configuration](http://groue.github.io/GRDB.swift/docs/5.11/Structs/Configuration.html) for more details. +See [Configuration](http://groue.github.io/GRDB.swift/docs/5.12/Structs/Configuration.html) for more details. ## Database Pools @@ -590,7 +590,7 @@ let dbPool = try DatabasePool( configuration: config) ``` -See [Configuration](http://groue.github.io/GRDB.swift/docs/5.11/Structs/Configuration.html) for more details. +See [Configuration](http://groue.github.io/GRDB.swift/docs/5.12/Structs/Configuration.html) for more details. Database pools are more memory-hungry than database queues. See [Memory Management](#memory-management) for more information. @@ -650,7 +650,7 @@ try dbQueue.write { db in } ``` -The `?` and colon-prefixed keys like `:score` in the SQL query are the **statements arguments**. You pass arguments with arrays or dictionaries, as in the example above. See [Values](#values) for more information on supported arguments types (Bool, Int, String, Date, Swift enums, etc.), and [StatementArguments](http://groue.github.io/GRDB.swift/docs/5.11/Structs/StatementArguments.html) for a detailed documentation of SQLite arguments. +The `?` and colon-prefixed keys like `:score` in the SQL query are the **statements arguments**. You pass arguments with arrays or dictionaries, as in the example above. See [Values](#values) for more information on supported arguments types (Bool, Int, String, Date, Swift enums, etc.), and [StatementArguments](http://groue.github.io/GRDB.swift/docs/5.12/Structs/StatementArguments.html) for a detailed documentation of SQLite arguments. You can also embed query arguments right into your SQL queries, with the `literal` argument label, as in the example below. See [SQL Interpolation] for more details. @@ -908,7 +908,7 @@ try dbQueue.read { db in let dictionary = try Dictionary(uniqueKeysWithValues: cursor) ``` -- **Cursors adopt the [Cursor](http://groue.github.io/GRDB.swift/docs/5.11/Protocols/Cursor.html) protocol, which looks a lot like standard [lazy sequences](https://developer.apple.com/reference/swift/lazysequenceprotocol) of Swift.** As such, cursors come with many convenience methods: `compactMap`, `contains`, `dropFirst`, `dropLast`, `drop(while:)`, `enumerated`, `filter`, `first`, `flatMap`, `forEach`, `joined`, `joined(separator:)`, `max`, `max(by:)`, `min`, `min(by:)`, `map`, `prefix`, `prefix(while:)`, `reduce`, `reduce(into:)`, `suffix`: +- **Cursors adopt the [Cursor](http://groue.github.io/GRDB.swift/docs/5.12/Protocols/Cursor.html) protocol, which looks a lot like standard [lazy sequences](https://developer.apple.com/reference/swift/lazysequenceprotocol) of Swift.** As such, cursors come with many convenience methods: `compactMap`, `contains`, `dropFirst`, `dropLast`, `drop(while:)`, `enumerated`, `filter`, `first`, `flatMap`, `forEach`, `joined`, `joined(separator:)`, `max`, `max(by:)`, `min`, `min(by:)`, `map`, `prefix`, `prefix(while:)`, `reduce`, `reduce(into:)`, `suffix`: ```swift // Prints all Github links @@ -987,7 +987,7 @@ let rows = try Row.fetchAll(db, arguments: ["name": "Arthur"]) ``` -See [Values](#values) for more information on supported arguments types (Bool, Int, String, Date, Swift enums, etc.), and [StatementArguments](http://groue.github.io/GRDB.swift/docs/5.11/Structs/StatementArguments.html) for a detailed documentation of SQLite arguments. +See [Values](#values) for more information on supported arguments types (Bool, Int, String, Date, Swift enums, etc.), and [StatementArguments](http://groue.github.io/GRDB.swift/docs/5.12/Structs/StatementArguments.html) for a detailed documentation of SQLite arguments. Unlike row arrays that contain copies of the database rows, row cursors are close to the SQLite metal, and require a little care: @@ -1272,7 +1272,7 @@ GRDB ships with built-in support for the following value types: - Generally speaking, all types that adopt the [DatabaseValueConvertible](#custom-value-types) protocol. -Values can be used as [statement arguments](http://groue.github.io/GRDB.swift/docs/5.11/Structs/StatementArguments.html): +Values can be used as [statement arguments](http://groue.github.io/GRDB.swift/docs/5.12/Structs/StatementArguments.html): ```swift let url: URL = ... @@ -1719,7 +1719,7 @@ try dbQueue.inDatabase { db in // or dbPool.writeWithoutTransaction } ``` -Transactions can't be left opened unless you set the [allowsUnsafeTransactions](http://groue.github.io/GRDB.swift/docs/5.11/Structs/Configuration.html) configuration flag: +Transactions can't be left opened unless you set the [allowsUnsafeTransactions](http://groue.github.io/GRDB.swift/docs/5.12/Structs/Configuration.html) configuration flag: ```swift // fatal error: A transaction has been left opened at the end of a database access @@ -1831,7 +1831,7 @@ try dbQueue.write { db in } ``` -The `?` and colon-prefixed keys like `:name` in the SQL query are the statement arguments. You set them with arrays or dictionaries (arguments are actually of type [StatementArguments](http://groue.github.io/GRDB.swift/docs/5.11/Structs/StatementArguments.html), which happens to adopt the ExpressibleByArrayLiteral and ExpressibleByDictionaryLiteral protocols). +The `?` and colon-prefixed keys like `:name` in the SQL query are the statement arguments. You set them with arrays or dictionaries (arguments are actually of type [StatementArguments](http://groue.github.io/GRDB.swift/docs/5.12/Structs/StatementArguments.html), which happens to adopt the ExpressibleByArrayLiteral and ExpressibleByDictionaryLiteral protocols). ```swift insertStatement.arguments = ["name": "Arthur", "score": 1000] @@ -1914,7 +1914,7 @@ See also `Database.execute(sql:)` in the [Executing Updates](#executing-updates) > :point_up: **Note**: it is a programmer error to reuse a prepared statement that has failed: GRDB may crash if you do so. -For more information about prepared statements, see the [Statement reference](http://groue.github.io/GRDB.swift/docs/5.11/Classes/Statement.html). +For more information about prepared statements, see the [Statement reference](http://groue.github.io/GRDB.swift/docs/5.12/Classes/Statement.html). ### Prepared Statements Cache @@ -2657,7 +2657,7 @@ try Place.fetchSet(db, sql: "SELECT ...", arguments:...) // Set try Place.fetchOne(db, sql: "SELECT ...", arguments:...) // Place? ``` -See [fetching methods](#fetching-methods) for information about the `fetchCursor`, `fetchAll`, `fetchSet` and `fetchOne` methods. See [StatementArguments](http://groue.github.io/GRDB.swift/docs/5.11/Structs/StatementArguments.html) for more information about the query arguments. +See [fetching methods](#fetching-methods) for information about the `fetchCursor`, `fetchAll`, `fetchSet` and `fetchOne` methods. See [StatementArguments](http://groue.github.io/GRDB.swift/docs/5.12/Structs/StatementArguments.html) for more information about the query arguments. > :point_up: **Note**: for performance reasons, the same row argument to `init(row:)` is reused during the iteration of a fetch query. If you want to keep the row for later use, make sure to store a copy: `self.row = row.copy()`. @@ -3091,7 +3091,7 @@ protocol EncodableRecord { } ``` -See [DatabaseColumnDecodingStrategy](https://groue.github.io/GRDB.swift/docs/5.11/Enums/DatabaseColumnDecodingStrategy.html), [DatabaseColumnEncodingStrategy](https://groue.github.io/GRDB.swift/docs/5.11/Enums/DatabaseColumnEncodingStrategy.html), and [DatabaseUUIDEncodingStrategy](https://groue.github.io/GRDB.swift/docs/5.11/Enums/DatabaseUUIDEncodingStrategy.html) to learn about all available strategies. +See [DatabaseColumnDecodingStrategy](https://groue.github.io/GRDB.swift/docs/5.12/Enums/DatabaseColumnDecodingStrategy.html), [DatabaseColumnEncodingStrategy](https://groue.github.io/GRDB.swift/docs/5.12/Enums/DatabaseColumnEncodingStrategy.html), and [DatabaseUUIDEncodingStrategy](https://groue.github.io/GRDB.swift/docs/5.12/Enums/DatabaseUUIDEncodingStrategy.html) to learn about all available strategies. ### Date and UUID Coding Strategies @@ -3113,7 +3113,7 @@ protocol EncodableRecord { } ``` -See [DatabaseDateDecodingStrategy](https://groue.github.io/GRDB.swift/docs/5.11/Enums/DatabaseDateDecodingStrategy.html), [DatabaseDateEncodingStrategy](https://groue.github.io/GRDB.swift/docs/5.11/Enums/DatabaseDateEncodingStrategy.html), and [DatabaseUUIDEncodingStrategy](https://groue.github.io/GRDB.swift/docs/5.11/Enums/DatabaseUUIDEncodingStrategy.html) to learn about all available strategies. +See [DatabaseDateDecodingStrategy](https://groue.github.io/GRDB.swift/docs/5.12/Enums/DatabaseDateDecodingStrategy.html), [DatabaseDateEncodingStrategy](https://groue.github.io/GRDB.swift/docs/5.12/Enums/DatabaseDateEncodingStrategy.html), and [DatabaseUUIDEncodingStrategy](https://groue.github.io/GRDB.swift/docs/5.12/Enums/DatabaseUUIDEncodingStrategy.html) to learn about all available strategies. > :point_up: **Note**: there is no customization of uuid decoding, because UUID can already decode all its encoded variants (16-bytes blobs, and uuid strings). @@ -4644,7 +4644,7 @@ Player // SELECT * FROM player ``` -Raw SQL snippets are also accepted, with eventual [arguments](http://groue.github.io/GRDB.swift/docs/5.11/Structs/StatementArguments.html): +Raw SQL snippets are also accepted, with eventual [arguments](http://groue.github.io/GRDB.swift/docs/5.12/Structs/StatementArguments.html): ```swift // SELECT DATE(creationDate), COUNT(*) FROM player WHERE name = 'Arthur' GROUP BY date(creationDate) @@ -5363,7 +5363,7 @@ try Player.customRequest().fetchAll(db) // [Player] - The `adapted(_:)` method eases the consumption of complex rows with [row adapters](#row-adapters). See [Joined Queries Support](#joined-queries-support) for some sample code that uses this method. -- [AnyFetchRequest](http://groue.github.io/GRDB.swift/docs/5.11/Structs/AnyFetchRequest.html): a type-erased request. +- [AnyFetchRequest](http://groue.github.io/GRDB.swift/docs/5.12/Structs/AnyFetchRequest.html): a type-erased request. ## Joined Queries Support @@ -6541,7 +6541,7 @@ After `stopObservingDatabaseChangesUntilNextTransaction()`, the `databaseDidChan ### DatabaseRegion -**[DatabaseRegion](https://groue.github.io/GRDB.swift/docs/5.11/Structs/DatabaseRegion.html) is a type that helps observing changes in the results of a database [request](#requests)**. +**[DatabaseRegion](https://groue.github.io/GRDB.swift/docs/5.12/Structs/DatabaseRegion.html) is a type that helps observing changes in the results of a database [request](#requests)**. A request knows which database modifications can impact its results. It can communicate this information to [transaction observers](#transactionobserver-protocol) by the way of a DatabaseRegion. @@ -6551,7 +6551,7 @@ DatabaseRegion fuels, for example, [ValueObservation and DatabaseRegionObservati For example, if you observe the region of `Player.select(max(Column("score")))`, then you'll get be notified of all changes performed on the `score` column of the `player` table (updates, insertions and deletions), even if they do not modify the value of the maximum score. However, you will not get any notification for changes performed on other database tables, or updates to other columns of the player table. -For more details, see the [reference](http://groue.github.io/GRDB.swift/docs/5.11/Structs/DatabaseRegion.html#/s:4GRDB14DatabaseRegionV10isModified2bySbAA0B5EventV_tF). +For more details, see the [reference](http://groue.github.io/GRDB.swift/docs/5.12/Structs/DatabaseRegion.html#/s:4GRDB14DatabaseRegionV10isModified2bySbAA0B5EventV_tF). #### The DatabaseRegionConvertible Protocol @@ -7671,7 +7671,7 @@ try snapshot2.read { db in ### DatabaseWriter and DatabaseReader Protocols -Both DatabaseQueue and DatabasePool adopt the [DatabaseReader](http://groue.github.io/GRDB.swift/docs/5.11/Protocols/DatabaseReader.html) and [DatabaseWriter](http://groue.github.io/GRDB.swift/docs/5.11/Protocols/DatabaseWriter.html) protocols. DatabaseSnapshot adopts DatabaseReader only. +Both DatabaseQueue and DatabasePool adopt the [DatabaseReader](http://groue.github.io/GRDB.swift/docs/5.12/Protocols/DatabaseReader.html) and [DatabaseWriter](http://groue.github.io/GRDB.swift/docs/5.12/Protocols/DatabaseWriter.html) protocols. DatabaseSnapshot adopts DatabaseReader only. These protocols provide a unified API that let you write generic code that targets all concurrency modes. They fuel, for example: @@ -8352,7 +8352,7 @@ When this is the case, there are two possible explanations: try db.execute(sql: "UPDATE player SET name = ?", arguments: [name]) ``` -For more information, see [Double-quoted String Literals Are Accepted](https://sqlite.org/quirks.html#dblquote), and [Configuration.acceptsDoubleQuotedStringLiterals](http://groue.github.io/GRDB.swift/docs/5.11/Structs/Configuration.html#/s:4GRDB13ConfigurationV33acceptsDoubleQuotedStringLiteralsSbvp). +For more information, see [Double-quoted String Literals Are Accepted](https://sqlite.org/quirks.html#dblquote), and [Configuration.acceptsDoubleQuotedStringLiterals](http://groue.github.io/GRDB.swift/docs/5.12/Structs/Configuration.html#/s:4GRDB13ConfigurationV33acceptsDoubleQuotedStringLiteralsSbvp). @@ -8520,7 +8520,7 @@ This chapter has been superseded by [ValueObservation] and [DatabaseRegionObserv [Sharing a Database]: Documentation/SharingADatabase.md [FAQ]: #faq [Database Observation]: #database-changes-observation -[SQLRequest]: http://groue.github.io/GRDB.swift/docs/5.11/Structs/SQLRequest.html +[SQLRequest]: http://groue.github.io/GRDB.swift/docs/5.12/Structs/SQLRequest.html [SQL literal]: Documentation/SQLInterpolation.md#sql-literal [Identifiable]: https://developer.apple.com/documentation/swift/identifiable [Query Interface Organization]: Documentation/QueryInterfaceOrganization.md diff --git a/Support/Info.plist b/Support/Info.plist index c4610188c..6aa6195ad 100644 --- a/Support/Info.plist +++ b/Support/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 5.11.0 + 5.12.0 CFBundleSignature ???? CFBundleVersion