From 2858b803d089a7880e12eb85b0ff0732d2f3b1b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 21 Aug 2021 12:25:04 +0200 Subject: [PATCH 01/19] Remove useless qualifiers SQLRequest and CommonTableExpression are by default --- .../Contents.swift | 6 +- GRDB/Core/DatabaseValueConvertible.swift | 14 +-- GRDB/Core/Row.swift | 8 +- GRDB/Core/StatementColumnConvertible.swift | 14 +-- .../Request/CommonTableExpression.swift | 18 ++-- GRDB/Record/FetchableRecord.swift | 8 +- README.md | 2 +- .../DatabaseValueConvertibleFetchTests.swift | 92 +++++++++---------- .../FetchableRecordDecodableTests.swift | 8 +- Tests/GRDBTests/FetchableRecordTests.swift | 52 +++++------ 10 files changed, 112 insertions(+), 110 deletions(-) diff --git a/Documentation/Playgrounds/CustomizedDecodingOfDatabaseRows.playground/Contents.swift b/Documentation/Playgrounds/CustomizedDecodingOfDatabaseRows.playground/Contents.swift index ca53da88d..ccda172fd 100644 --- a/Documentation/Playgrounds/CustomizedDecodingOfDatabaseRows.playground/Contents.swift +++ b/Documentation/Playgrounds/CustomizedDecodingOfDatabaseRows.playground/Contents.swift @@ -368,15 +368,15 @@ extension MyDatabaseDecoder { // MARK: - Fetch from SQL static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> MapCursor { - try fetchCursor(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) + try fetchCursor(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [DecodedType] { - try fetchAll(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) + try fetchAll(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } static func fetchOne(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> DecodedType? { - try fetchOne(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) + try fetchOne(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } } diff --git a/GRDB/Core/DatabaseValueConvertible.swift b/GRDB/Core/DatabaseValueConvertible.swift index 2347e6e9e..80f107a47 100644 --- a/GRDB/Core/DatabaseValueConvertible.swift +++ b/GRDB/Core/DatabaseValueConvertible.swift @@ -425,7 +425,7 @@ extension DatabaseValueConvertible { adapter: RowAdapter? = nil) throws -> DatabaseValueCursor { - try fetchCursor(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) + try fetchCursor(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } /// Returns an array of values fetched from an SQL query. @@ -446,7 +446,7 @@ extension DatabaseValueConvertible { adapter: RowAdapter? = nil) throws -> [Self] { - try fetchAll(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) + try fetchAll(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } /// Returns a single value fetched from an SQL query. @@ -470,7 +470,7 @@ extension DatabaseValueConvertible { adapter: RowAdapter? = nil) throws -> Self? { - try fetchOne(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) + try fetchOne(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } } @@ -493,7 +493,7 @@ extension DatabaseValueConvertible where Self: Hashable { adapter: RowAdapter? = nil) throws -> Set { - try fetchSet(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) + try fetchSet(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } } @@ -757,7 +757,7 @@ extension Optional where Wrapped: DatabaseValueConvertible { adapter: RowAdapter? = nil) throws -> NullableDatabaseValueCursor { - try fetchCursor(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) + try fetchCursor(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } /// Returns an array of optional values fetched from an SQL query. @@ -778,7 +778,7 @@ extension Optional where Wrapped: DatabaseValueConvertible { adapter: RowAdapter? = nil) throws -> [Wrapped?] { - try fetchAll(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) + try fetchAll(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } } @@ -801,7 +801,7 @@ extension Optional where Wrapped: DatabaseValueConvertible & Hashable { adapter: RowAdapter? = nil) throws -> Set { - try fetchSet(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) + try fetchSet(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } } diff --git a/GRDB/Core/Row.swift b/GRDB/Core/Row.swift index 01fcb86ad..c1d6469ce 100644 --- a/GRDB/Core/Row.swift +++ b/GRDB/Core/Row.swift @@ -1400,7 +1400,7 @@ extension Row { adapter: RowAdapter? = nil) throws -> RowCursor { - try fetchCursor(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) + try fetchCursor(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } /// Returns an array of rows fetched from an SQL query. @@ -1425,7 +1425,7 @@ extension Row { adapter: RowAdapter? = nil) throws -> [Row] { - try fetchAll(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) + try fetchAll(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } /// Returns a set of rows fetched from an SQL query. @@ -1450,7 +1450,7 @@ extension Row { adapter: RowAdapter? = nil) throws -> Set { - try fetchSet(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) + try fetchSet(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } /// Returns a single row fetched from an SQL query. @@ -1475,7 +1475,7 @@ extension Row { adapter: RowAdapter? = nil) throws -> Row? { - try fetchOne(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) + try fetchOne(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } } diff --git a/GRDB/Core/StatementColumnConvertible.swift b/GRDB/Core/StatementColumnConvertible.swift index e4bdb7709..278f5e239 100644 --- a/GRDB/Core/StatementColumnConvertible.swift +++ b/GRDB/Core/StatementColumnConvertible.swift @@ -419,7 +419,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { adapter: RowAdapter? = nil) throws -> FastDatabaseValueCursor { - try fetchCursor(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) + try fetchCursor(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } /// Returns an array of values fetched from an SQL query. @@ -440,7 +440,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { adapter: RowAdapter? = nil) throws -> [Self] { - try fetchAll(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) + try fetchAll(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } /// Returns a single value fetched from an SQL query. @@ -461,7 +461,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { adapter: RowAdapter? = nil) throws -> Self? { - try fetchOne(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) + try fetchOne(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } } @@ -484,7 +484,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible & Hash adapter: RowAdapter? = nil) throws -> Set { - try fetchSet(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) + try fetchSet(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } } @@ -747,7 +747,7 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv adapter: RowAdapter? = nil) throws -> FastNullableDatabaseValueCursor { - try fetchCursor(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) + try fetchCursor(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } /// Returns an array of optional values fetched from an SQL query. @@ -768,7 +768,7 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv adapter: RowAdapter? = nil) throws -> [Wrapped?] { - try fetchAll(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) + try fetchAll(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } } @@ -791,7 +791,7 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv adapter: RowAdapter? = nil) throws -> Set { - try fetchSet(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) + try fetchSet(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } } diff --git a/GRDB/QueryInterface/Request/CommonTableExpression.swift b/GRDB/QueryInterface/Request/CommonTableExpression.swift index 5e5389e0c..293a7b9a0 100644 --- a/GRDB/QueryInterface/Request/CommonTableExpression.swift +++ b/GRDB/QueryInterface/Request/CommonTableExpression.swift @@ -19,14 +19,16 @@ public struct CommonTableExpression { /// For example: /// /// // WITH p AS (SELECT * FROM player) ... - /// let p = CommonTableExpression( + /// let p = CommonTableExpression( /// named: "p", - /// request: Player.all()) + /// request: Player.all(), + /// type: Void.self) /// /// // WITH p AS (SELECT * FROM player) ... - /// let p = CommonTableExpression( + /// let p = CommonTableExpression( /// named: "p", - /// request: SQLRequest(sql: "SELECT * FROM player")) + /// request: SQLRequest(sql: "SELECT * FROM player"), + /// type: Void.self) /// /// - parameter recursive: Whether this common table expression needs a /// `WITH RECURSIVE` sql clause. @@ -113,7 +115,7 @@ extension CommonTableExpression { recursive: recursive, named: tableName, columns: columns, - request: SQLRequest(sql: sql, arguments: arguments), + request: SQLRequest(sql: sql, arguments: arguments), type: RowDecoder.self) } @@ -144,7 +146,7 @@ extension CommonTableExpression { recursive: recursive, named: tableName, columns: columns, - request: SQLRequest(literal: sqlLiteral), + request: SQLRequest(literal: sqlLiteral), type: RowDecoder.self) } } @@ -213,7 +215,7 @@ extension CommonTableExpression where RowDecoder == Row { recursive: recursive, named: tableName, columns: columns, - request: SQLRequest(sql: sql, arguments: arguments), + request: SQLRequest(sql: sql, arguments: arguments), type: Row.self) } @@ -244,7 +246,7 @@ extension CommonTableExpression where RowDecoder == Row { recursive: recursive, named: tableName, columns: columns, - request: SQLRequest(literal: sqlLiteral), + request: SQLRequest(literal: sqlLiteral), type: Row.self) } } diff --git a/GRDB/Record/FetchableRecord.swift b/GRDB/Record/FetchableRecord.swift index 73213ca42..b23ca7ea6 100644 --- a/GRDB/Record/FetchableRecord.swift +++ b/GRDB/Record/FetchableRecord.swift @@ -254,7 +254,7 @@ extension FetchableRecord { adapter: RowAdapter? = nil) throws -> RecordCursor { - try fetchCursor(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) + try fetchCursor(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } /// Returns an array of records fetched from an SQL query. @@ -275,7 +275,7 @@ extension FetchableRecord { adapter: RowAdapter? = nil) throws -> [Self] { - try fetchAll(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) + try fetchAll(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } /// Returns a single record fetched from an SQL query. @@ -296,7 +296,7 @@ extension FetchableRecord { adapter: RowAdapter? = nil) throws -> Self? { - try fetchOne(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) + try fetchOne(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } } @@ -319,7 +319,7 @@ extension FetchableRecord where Self: Hashable { adapter: RowAdapter? = nil) throws -> Set { - try fetchSet(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) + try fetchSet(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } } diff --git a/README.md b/README.md index 6ff994929..5e301a1d4 100644 --- a/README.md +++ b/README.md @@ -4834,7 +4834,7 @@ GRDB comes with a Swift version of many SQLite [built-in operators](https://sqli ```swift // WITH selectedName AS (...) // SELECT * FROM player WHERE name IN selectedName - let cte = CommonTableExpression(named: "selectedName", ...) + let cte = CommonTableExpression(named: "selectedName", ...) Player .with(cte) .filter(cte.contains(nameColumn)) diff --git a/Tests/GRDBTests/DatabaseValueConvertibleFetchTests.swift b/Tests/GRDBTests/DatabaseValueConvertibleFetchTests.swift index 8c1765873..3a80e683a 100644 --- a/Tests/GRDBTests/DatabaseValueConvertibleFetchTests.swift +++ b/Tests/GRDBTests/DatabaseValueConvertibleFetchTests.swift @@ -34,7 +34,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let statement = try db.makeStatement(sql: sql) try test(Fetched.fetchCursor(db, sql: sql)) try test(Fetched.fetchCursor(statement)) - try test(Fetched.fetchCursor(db, SQLRequest(sql: sql))) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql))) try test(SQLRequest(sql: sql).fetchCursor(db)) } do { @@ -43,7 +43,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Fetched.fetchCursor(db, sql: sql, adapter: adapter)) try test(Fetched.fetchCursor(statement, adapter: adapter)) - try test(Fetched.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter))) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter))) try test(SQLRequest(sql: sql, adapter: adapter).fetchCursor(db)) } } @@ -86,7 +86,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let sql = "SELECT throw()" try test(Fetched.fetchCursor(db, sql: sql), sql: sql) try test(Fetched.fetchCursor(db.makeStatement(sql: sql)), sql: sql) - try test(Fetched.fetchCursor(db, SQLRequest(sql: sql)), sql: sql) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql)), sql: sql) try test(SQLRequest(sql: sql).fetchCursor(db), sql: sql) } do { @@ -94,7 +94,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Fetched.fetchCursor(db, sql: sql, adapter: adapter), sql: sql) try test(Fetched.fetchCursor(db.makeStatement(sql: sql), adapter: adapter), sql: sql) - try test(Fetched.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) try test(SQLRequest(sql: sql, adapter: adapter).fetchCursor(db), sql: sql) } } @@ -118,7 +118,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let sql = "SELECT * FROM nonExistingTable" try test(Fetched.fetchCursor(db, sql: sql), sql: sql) try test(Fetched.fetchCursor(db.makeStatement(sql: sql)), sql: sql) - try test(Fetched.fetchCursor(db, SQLRequest(sql: sql)), sql: sql) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql)), sql: sql) try test(SQLRequest(sql: sql).fetchCursor(db), sql: sql) } do { @@ -126,7 +126,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Fetched.fetchCursor(db, sql: sql, adapter: adapter), sql: sql) try test(Fetched.fetchCursor(db.makeStatement(sql: sql), adapter: adapter), sql: sql) - try test(Fetched.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) try test(SQLRequest(sql: sql, adapter: adapter).fetchCursor(db), sql: sql) } } @@ -143,7 +143,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let statement = try db.makeStatement(sql: sql) try test(Fetched.fetchAll(db, sql: sql)) try test(Fetched.fetchAll(statement)) - try test(Fetched.fetchAll(db, SQLRequest(sql: sql))) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql))) try test(SQLRequest(sql: sql).fetchAll(db)) } do { @@ -152,7 +152,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Fetched.fetchAll(db, sql: sql, adapter: adapter)) try test(Fetched.fetchAll(statement, adapter: adapter)) - try test(Fetched.fetchAll(db, SQLRequest(sql: sql, adapter: adapter))) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql, adapter: adapter))) try test(SQLRequest(sql: sql, adapter: adapter).fetchAll(db)) } } @@ -187,7 +187,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let sql = "SELECT throw()" try test(Fetched.fetchAll(db, sql: sql), sql: sql) try test(Fetched.fetchAll(db.makeStatement(sql: sql)), sql: sql) - try test(Fetched.fetchAll(db, SQLRequest(sql: sql)), sql: sql) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql)), sql: sql) try test(SQLRequest(sql: sql).fetchAll(db), sql: sql) } do { @@ -195,7 +195,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Fetched.fetchAll(db, sql: sql, adapter: adapter), sql: sql) try test(Fetched.fetchAll(db.makeStatement(sql: sql), adapter: adapter), sql: sql) - try test(Fetched.fetchAll(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) try test(SQLRequest(sql: sql, adapter: adapter).fetchAll(db), sql: sql) } } @@ -219,7 +219,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let sql = "SELECT * FROM nonExistingTable" try test(Fetched.fetchAll(db, sql: sql), sql: sql) try test(Fetched.fetchAll(db.makeStatement(sql: sql)), sql: sql) - try test(Fetched.fetchAll(db, SQLRequest(sql: sql)), sql: sql) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql)), sql: sql) try test(SQLRequest(sql: sql).fetchAll(db), sql: sql) } do { @@ -227,7 +227,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Fetched.fetchAll(db, sql: sql, adapter: adapter), sql: sql) try test(Fetched.fetchAll(db.makeStatement(sql: sql), adapter: adapter), sql: sql) - try test(Fetched.fetchAll(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) try test(SQLRequest(sql: sql, adapter: adapter).fetchAll(db), sql: sql) } } @@ -244,7 +244,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let statement = try db.makeStatement(sql: sql) try test(Fetched.fetchSet(db, sql: sql)) try test(Fetched.fetchSet(statement)) - try test(Fetched.fetchSet(db, SQLRequest(sql: sql))) + try test(Fetched.fetchSet(db, SQLRequest(sql: sql))) try test(SQLRequest(sql: sql).fetchSet(db)) } do { @@ -253,7 +253,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Fetched.fetchSet(db, sql: sql, adapter: adapter)) try test(Fetched.fetchSet(statement, adapter: adapter)) - try test(Fetched.fetchSet(db, SQLRequest(sql: sql, adapter: adapter))) + try test(Fetched.fetchSet(db, SQLRequest(sql: sql, adapter: adapter))) try test(SQLRequest(sql: sql, adapter: adapter).fetchSet(db)) } } @@ -288,7 +288,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let sql = "SELECT throw()" try test(Fetched.fetchSet(db, sql: sql), sql: sql) try test(Fetched.fetchSet(db.makeStatement(sql: sql)), sql: sql) - try test(Fetched.fetchSet(db, SQLRequest(sql: sql)), sql: sql) + try test(Fetched.fetchSet(db, SQLRequest(sql: sql)), sql: sql) try test(SQLRequest(sql: sql).fetchSet(db), sql: sql) } do { @@ -296,7 +296,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Fetched.fetchSet(db, sql: sql, adapter: adapter), sql: sql) try test(Fetched.fetchSet(db.makeStatement(sql: sql), adapter: adapter), sql: sql) - try test(Fetched.fetchSet(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(Fetched.fetchSet(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) try test(SQLRequest(sql: sql, adapter: adapter).fetchSet(db), sql: sql) } } @@ -320,7 +320,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let sql = "SELECT * FROM nonExistingTable" try test(Fetched.fetchSet(db, sql: sql), sql: sql) try test(Fetched.fetchSet(db.makeStatement(sql: sql)), sql: sql) - try test(Fetched.fetchSet(db, SQLRequest(sql: sql)), sql: sql) + try test(Fetched.fetchSet(db, SQLRequest(sql: sql)), sql: sql) try test(SQLRequest(sql: sql).fetchSet(db), sql: sql) } do { @@ -328,7 +328,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Fetched.fetchSet(db, sql: sql, adapter: adapter), sql: sql) try test(Fetched.fetchSet(db.makeStatement(sql: sql), adapter: adapter), sql: sql) - try test(Fetched.fetchSet(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(Fetched.fetchSet(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) try test(SQLRequest(sql: sql, adapter: adapter).fetchSet(db), sql: sql) } } @@ -346,7 +346,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let statement = try db.makeStatement(sql: sql) try test(Fetched.fetchOne(db, sql: sql)) try test(Fetched.fetchOne(statement)) - try test(Fetched.fetchOne(db, SQLRequest(sql: sql))) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql))) try test(SQLRequest(sql: sql).fetchOne(db)) } do { @@ -355,7 +355,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Fetched.fetchOne(db, sql: sql, adapter: adapter)) try test(Fetched.fetchOne(statement, adapter: adapter)) - try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter))) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter))) try test(SQLRequest(sql: sql, adapter: adapter).fetchOne(db)) } } @@ -368,7 +368,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let statement = try db.makeStatement(sql: sql) try test(Fetched.fetchOne(db, sql: sql)) try test(Fetched.fetchOne(statement)) - try test(Fetched.fetchOne(db, SQLRequest(sql: sql))) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql))) try test(SQLRequest(sql: sql).fetchOne(db)) } do { @@ -377,7 +377,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Fetched.fetchOne(db, sql: sql, adapter: adapter)) try test(Fetched.fetchOne(statement, adapter: adapter)) - try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter))) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter))) try test(SQLRequest(sql: sql, adapter: adapter).fetchOne(db)) } } @@ -390,7 +390,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let statement = try db.makeStatement(sql: sql) try test(Fetched.fetchOne(db, sql: sql)) try test(Fetched.fetchOne(statement)) - try test(Fetched.fetchOne(db, SQLRequest(sql: sql))) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql))) try test(SQLRequest(sql: sql).fetchOne(db)) } do { @@ -399,7 +399,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Fetched.fetchOne(db, sql: sql, adapter: adapter)) try test(Fetched.fetchOne(statement, adapter: adapter)) - try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter))) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter))) try test(SQLRequest(sql: sql, adapter: adapter).fetchOne(db)) } } @@ -435,7 +435,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let sql = "SELECT throw()" try test(Fetched.fetchOne(db, sql: sql), sql: sql) try test(Fetched.fetchOne(db.makeStatement(sql: sql)), sql: sql) - try test(Fetched.fetchOne(db, SQLRequest(sql: sql)), sql: sql) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql)), sql: sql) try test(SQLRequest(sql: sql).fetchOne(db), sql: sql) } do { @@ -443,7 +443,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Fetched.fetchOne(db, sql: sql, adapter: adapter), sql: sql) try test(Fetched.fetchOne(db.makeStatement(sql: sql), adapter: adapter), sql: sql) - try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) try test(SQLRequest(sql: sql, adapter: adapter).fetchOne(db), sql: sql) } } @@ -467,7 +467,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let sql = "SELECT * FROM nonExistingTable" try test(Fetched.fetchOne(db, sql: sql), sql: sql) try test(Fetched.fetchOne(db.makeStatement(sql: sql)), sql: sql) - try test(Fetched.fetchOne(db, SQLRequest(sql: sql)), sql: sql) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql)), sql: sql) try test(SQLRequest(sql: sql).fetchOne(db), sql: sql) } do { @@ -475,7 +475,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Fetched.fetchOne(db, sql: sql, adapter: adapter), sql: sql) try test(Fetched.fetchOne(db.makeStatement(sql: sql), adapter: adapter), sql: sql) - try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) try test(SQLRequest(sql: sql, adapter: adapter).fetchOne(db), sql: sql) } } @@ -497,7 +497,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let statement = try db.makeStatement(sql: sql) try test(Optional.fetchCursor(db, sql: sql)) try test(Optional.fetchCursor(statement)) - try test(Optional.fetchCursor(db, SQLRequest(sql: sql))) + try test(Optional.fetchCursor(db, SQLRequest(sql: sql))) try test(SQLRequest(sql: sql).fetchCursor(db)) } do { @@ -506,7 +506,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Optional.fetchCursor(db, sql: sql, adapter: adapter)) try test(Optional.fetchCursor(statement, adapter: adapter)) - try test(Optional.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter))) + try test(Optional.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter))) try test(SQLRequest(sql: sql, adapter: adapter).fetchCursor(db)) } } @@ -549,7 +549,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let sql = "SELECT throw()" try test(Optional.fetchCursor(db, sql: sql), sql: sql) try test(Optional.fetchCursor(db.makeStatement(sql: sql)), sql: sql) - try test(Optional.fetchCursor(db, SQLRequest(sql: sql)), sql: sql) + try test(Optional.fetchCursor(db, SQLRequest(sql: sql)), sql: sql) try test(SQLRequest(sql: sql).fetchCursor(db), sql: sql) } do { @@ -557,7 +557,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Optional.fetchCursor(db, sql: sql, adapter: adapter), sql: sql) try test(Optional.fetchCursor(db.makeStatement(sql: sql), adapter: adapter), sql: sql) - try test(Optional.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(Optional.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) try test(SQLRequest(sql: sql, adapter: adapter).fetchCursor(db), sql: sql) } } @@ -581,7 +581,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let sql = "SELECT * FROM nonExistingTable" try test(Optional.fetchCursor(db, sql: sql), sql: sql) try test(Optional.fetchCursor(db.makeStatement(sql: sql)), sql: sql) - try test(Optional.fetchCursor(db, SQLRequest(sql: sql)), sql: sql) + try test(Optional.fetchCursor(db, SQLRequest(sql: sql)), sql: sql) try test(SQLRequest(sql: sql).fetchCursor(db), sql: sql) } do { @@ -589,7 +589,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Optional.fetchCursor(db, sql: sql, adapter: adapter), sql: sql) try test(Optional.fetchCursor(db.makeStatement(sql: sql), adapter: adapter), sql: sql) - try test(Optional.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(Optional.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) try test(SQLRequest(sql: sql, adapter: adapter).fetchCursor(db), sql: sql) } } @@ -608,7 +608,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let statement = try db.makeStatement(sql: sql) try test(Optional.fetchAll(db, sql: sql)) try test(Optional.fetchAll(statement)) - try test(Optional.fetchAll(db, SQLRequest(sql: sql))) + try test(Optional.fetchAll(db, SQLRequest(sql: sql))) try test(SQLRequest(sql: sql).fetchAll(db)) } do { @@ -617,7 +617,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Optional.fetchAll(db, sql: sql, adapter: adapter)) try test(Optional.fetchAll(statement, adapter: adapter)) - try test(Optional.fetchAll(db, SQLRequest(sql: sql, adapter: adapter))) + try test(Optional.fetchAll(db, SQLRequest(sql: sql, adapter: adapter))) try test(SQLRequest(sql: sql, adapter: adapter).fetchAll(db)) } } @@ -652,7 +652,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let sql = "SELECT throw()" try test(Optional.fetchAll(db, sql: sql), sql: sql) try test(Optional.fetchAll(db.makeStatement(sql: sql)), sql: sql) - try test(Optional.fetchAll(db, SQLRequest(sql: sql)), sql: sql) + try test(Optional.fetchAll(db, SQLRequest(sql: sql)), sql: sql) try test(SQLRequest(sql: sql).fetchAll(db), sql: sql) } do { @@ -660,7 +660,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Optional.fetchAll(db, sql: sql, adapter: adapter), sql: sql) try test(Optional.fetchAll(db.makeStatement(sql: sql), adapter: adapter), sql: sql) - try test(Optional.fetchAll(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(Optional.fetchAll(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) try test(SQLRequest(sql: sql, adapter: adapter).fetchAll(db), sql: sql) } } @@ -684,7 +684,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let sql = "SELECT * FROM nonExistingTable" try test(Optional.fetchAll(db, sql: sql), sql: sql) try test(Optional.fetchAll(db.makeStatement(sql: sql)), sql: sql) - try test(Optional.fetchAll(db, SQLRequest(sql: sql)), sql: sql) + try test(Optional.fetchAll(db, SQLRequest(sql: sql)), sql: sql) try test(SQLRequest(sql: sql).fetchAll(db), sql: sql) } do { @@ -692,7 +692,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Optional.fetchAll(db, sql: sql, adapter: adapter), sql: sql) try test(Optional.fetchAll(db.makeStatement(sql: sql), adapter: adapter), sql: sql) - try test(Optional.fetchAll(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(Optional.fetchAll(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) try test(SQLRequest(sql: sql, adapter: adapter).fetchAll(db), sql: sql) } } @@ -709,7 +709,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let statement = try db.makeStatement(sql: sql) try test(Optional.fetchSet(db, sql: sql)) try test(Optional.fetchSet(statement)) - try test(Optional.fetchSet(db, SQLRequest(sql: sql))) + try test(Optional.fetchSet(db, SQLRequest(sql: sql))) try test(SQLRequest(sql: sql).fetchSet(db)) } do { @@ -718,7 +718,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Optional.fetchSet(db, sql: sql, adapter: adapter)) try test(Optional.fetchSet(statement, adapter: adapter)) - try test(Optional.fetchSet(db, SQLRequest(sql: sql, adapter: adapter))) + try test(Optional.fetchSet(db, SQLRequest(sql: sql, adapter: adapter))) try test(SQLRequest(sql: sql, adapter: adapter).fetchSet(db)) } } @@ -753,7 +753,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let sql = "SELECT throw()" try test(Optional.fetchSet(db, sql: sql), sql: sql) try test(Optional.fetchSet(db.makeStatement(sql: sql)), sql: sql) - try test(Optional.fetchSet(db, SQLRequest(sql: sql)), sql: sql) + try test(Optional.fetchSet(db, SQLRequest(sql: sql)), sql: sql) try test(SQLRequest(sql: sql).fetchSet(db), sql: sql) } do { @@ -761,7 +761,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Optional.fetchSet(db, sql: sql, adapter: adapter), sql: sql) try test(Optional.fetchSet(db.makeStatement(sql: sql), adapter: adapter), sql: sql) - try test(Optional.fetchSet(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(Optional.fetchSet(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) try test(SQLRequest(sql: sql, adapter: adapter).fetchSet(db), sql: sql) } } @@ -785,7 +785,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let sql = "SELECT * FROM nonExistingTable" try test(Optional.fetchSet(db, sql: sql), sql: sql) try test(Optional.fetchSet(db.makeStatement(sql: sql)), sql: sql) - try test(Optional.fetchSet(db, SQLRequest(sql: sql)), sql: sql) + try test(Optional.fetchSet(db, SQLRequest(sql: sql)), sql: sql) try test(SQLRequest(sql: sql).fetchSet(db), sql: sql) } do { @@ -793,7 +793,7 @@ class DatabaseValueConvertibleFetchTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Optional.fetchSet(db, sql: sql, adapter: adapter), sql: sql) try test(Optional.fetchSet(db.makeStatement(sql: sql), adapter: adapter), sql: sql) - try test(Optional.fetchSet(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(Optional.fetchSet(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) try test(SQLRequest(sql: sql, adapter: adapter).fetchSet(db), sql: sql) } } diff --git a/Tests/GRDBTests/FetchableRecordDecodableTests.swift b/Tests/GRDBTests/FetchableRecordDecodableTests.swift index 6b123d846..4a304aa6e 100644 --- a/Tests/GRDBTests/FetchableRecordDecodableTests.swift +++ b/Tests/GRDBTests/FetchableRecordDecodableTests.swift @@ -933,7 +933,7 @@ extension FetchableRecordDecodableTests { } let adapter = SuffixRowAdapter(fromIndex: 1).addingScopes(["nestedKeyed": RangeRowAdapter(0..<1)]) - let request = SQLRequest( + let request = SQLRequest( sql: "SELECT ? AS name, ? AS nestedSingle, ? AS nestedUnkeyed", arguments: ["foo", "bar", "[\"baz\"]"], adapter: adapter) @@ -969,7 +969,7 @@ extension FetchableRecordDecodableTests { XCTAssertNil(record.nestedUnkeyed.context) } - let request = SQLRequest( + let request = SQLRequest( sql: "SELECT ? AS nestedKeyed, ? AS nestedSingle, ? AS nestedUnkeyed", arguments: ["{\"name\":\"foo\"}", "bar", "[\"baz\"]"]) @@ -1005,7 +1005,7 @@ extension FetchableRecordDecodableTests { } let adapter = SuffixRowAdapter(fromIndex: 1).addingScopes(["nestedKeyed": RangeRowAdapter(0..<1)]) - let request = SQLRequest( + let request = SQLRequest( sql: "SELECT ? AS name, ? AS nestedSingle, ? AS nestedUnkeyed", arguments: ["foo", "bar", "[\"baz\"]"], adapter: adapter) @@ -1041,7 +1041,7 @@ extension FetchableRecordDecodableTests { XCTAssertEqual(record.nestedUnkeyed.context, "JSON column: nestedUnkeyed") } - let request = SQLRequest( + let request = SQLRequest( sql: "SELECT ? AS nestedKeyed, ? AS nestedSingle, ? AS nestedUnkeyed", arguments: ["{\"name\":\"foo\"}", "bar", "[\"baz\"]"]) diff --git a/Tests/GRDBTests/FetchableRecordTests.swift b/Tests/GRDBTests/FetchableRecordTests.swift index 7397e7b8b..4da399849 100644 --- a/Tests/GRDBTests/FetchableRecordTests.swift +++ b/Tests/GRDBTests/FetchableRecordTests.swift @@ -39,7 +39,7 @@ class FetchableRecordTests: GRDBTestCase { let statement = try db.makeStatement(sql: sql) try test(Fetched.fetchCursor(db, sql: sql)) try test(Fetched.fetchCursor(statement)) - try test(Fetched.fetchCursor(db, SQLRequest(sql: sql))) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql))) try test(SQLRequest(sql: sql).fetchCursor(db)) } do { @@ -48,7 +48,7 @@ class FetchableRecordTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Fetched.fetchCursor(db, sql: sql, adapter: adapter)) try test(Fetched.fetchCursor(statement, adapter: adapter)) - try test(Fetched.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter))) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter))) try test(SQLRequest(sql: sql, adapter: adapter).fetchCursor(db)) } } @@ -95,7 +95,7 @@ class FetchableRecordTests: GRDBTestCase { let sql = "SELECT throw(), NULL" try test(Fetched.fetchCursor(db, sql: sql), sql: sql) try test(Fetched.fetchCursor(db.makeStatement(sql: sql)), sql: sql) - try test(Fetched.fetchCursor(db, SQLRequest(sql: sql)), sql: sql) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql)), sql: sql) try test(SQLRequest(sql: sql).fetchCursor(db), sql: sql) } do { @@ -103,7 +103,7 @@ class FetchableRecordTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Fetched.fetchCursor(db, sql: sql, adapter: adapter), sql: sql) try test(Fetched.fetchCursor(db.makeStatement(sql: sql), adapter: adapter), sql: sql) - try test(Fetched.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) try test(SQLRequest(sql: sql, adapter: adapter).fetchCursor(db), sql: sql) } } @@ -127,7 +127,7 @@ class FetchableRecordTests: GRDBTestCase { let sql = "SELECT * FROM nonExistingTable" try test(Fetched.fetchCursor(db, sql: sql), sql: sql) try test(Fetched.fetchCursor(db.makeStatement(sql: sql)), sql: sql) - try test(Fetched.fetchCursor(db, SQLRequest(sql: sql)), sql: sql) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql)), sql: sql) try test(SQLRequest(sql: sql).fetchCursor(db), sql: sql) } do { @@ -135,7 +135,7 @@ class FetchableRecordTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Fetched.fetchCursor(db, sql: sql, adapter: adapter), sql: sql) try test(Fetched.fetchCursor(db.makeStatement(sql: sql), adapter: adapter), sql: sql) - try test(Fetched.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(Fetched.fetchCursor(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) try test(SQLRequest(sql: sql, adapter: adapter).fetchCursor(db), sql: sql) } } @@ -153,7 +153,7 @@ class FetchableRecordTests: GRDBTestCase { let statement = try db.makeStatement(sql: sql) try test(Fetched.fetchAll(db, sql: sql)) try test(Fetched.fetchAll(statement)) - try test(Fetched.fetchAll(db, SQLRequest(sql: sql))) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql))) try test(SQLRequest(sql: sql).fetchAll(db)) } do { @@ -162,7 +162,7 @@ class FetchableRecordTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Fetched.fetchAll(db, sql: sql, adapter: adapter)) try test(Fetched.fetchAll(statement, adapter: adapter)) - try test(Fetched.fetchAll(db, SQLRequest(sql: sql, adapter: adapter))) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql, adapter: adapter))) try test(SQLRequest(sql: sql, adapter: adapter).fetchAll(db)) } } @@ -200,7 +200,7 @@ class FetchableRecordTests: GRDBTestCase { let sql = "SELECT throw()" try test(Fetched.fetchAll(db, sql: sql), sql: sql) try test(Fetched.fetchAll(db.makeStatement(sql: sql)), sql: sql) - try test(Fetched.fetchAll(db, SQLRequest(sql: sql)), sql: sql) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql)), sql: sql) try test(SQLRequest(sql: sql).fetchAll(db), sql: sql) } do { @@ -208,7 +208,7 @@ class FetchableRecordTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Fetched.fetchAll(db, sql: sql, adapter: adapter), sql: sql) try test(Fetched.fetchAll(db.makeStatement(sql: sql), adapter: adapter), sql: sql) - try test(Fetched.fetchAll(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) try test(SQLRequest(sql: sql, adapter: adapter).fetchAll(db), sql: sql) } } @@ -232,7 +232,7 @@ class FetchableRecordTests: GRDBTestCase { let sql = "SELECT * FROM nonExistingTable" try test(Fetched.fetchAll(db, sql: sql), sql: sql) try test(Fetched.fetchAll(db.makeStatement(sql: sql)), sql: sql) - try test(Fetched.fetchAll(db, SQLRequest(sql: sql)), sql: sql) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql)), sql: sql) try test(SQLRequest(sql: sql).fetchAll(db), sql: sql) } do { @@ -240,7 +240,7 @@ class FetchableRecordTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Fetched.fetchAll(db, sql: sql, adapter: adapter), sql: sql) try test(Fetched.fetchAll(db.makeStatement(sql: sql), adapter: adapter), sql: sql) - try test(Fetched.fetchAll(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(Fetched.fetchAll(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) try test(SQLRequest(sql: sql, adapter: adapter).fetchAll(db), sql: sql) } } @@ -258,7 +258,7 @@ class FetchableRecordTests: GRDBTestCase { let statement = try db.makeStatement(sql: sql) try test(Fetched.fetchSet(db, sql: sql)) try test(Fetched.fetchSet(statement)) - try test(Fetched.fetchSet(db, SQLRequest(sql: sql))) + try test(Fetched.fetchSet(db, SQLRequest(sql: sql))) try test(SQLRequest(sql: sql).fetchSet(db)) } do { @@ -267,7 +267,7 @@ class FetchableRecordTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Fetched.fetchSet(db, sql: sql, adapter: adapter)) try test(Fetched.fetchSet(statement, adapter: adapter)) - try test(Fetched.fetchSet(db, SQLRequest(sql: sql, adapter: adapter))) + try test(Fetched.fetchSet(db, SQLRequest(sql: sql, adapter: adapter))) try test(SQLRequest(sql: sql, adapter: adapter).fetchSet(db)) } } @@ -305,7 +305,7 @@ class FetchableRecordTests: GRDBTestCase { let sql = "SELECT throw()" try test(Fetched.fetchSet(db, sql: sql), sql: sql) try test(Fetched.fetchSet(db.makeStatement(sql: sql)), sql: sql) - try test(Fetched.fetchSet(db, SQLRequest(sql: sql)), sql: sql) + try test(Fetched.fetchSet(db, SQLRequest(sql: sql)), sql: sql) try test(SQLRequest(sql: sql).fetchSet(db), sql: sql) } do { @@ -313,7 +313,7 @@ class FetchableRecordTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Fetched.fetchSet(db, sql: sql, adapter: adapter), sql: sql) try test(Fetched.fetchSet(db.makeStatement(sql: sql), adapter: adapter), sql: sql) - try test(Fetched.fetchSet(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(Fetched.fetchSet(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) try test(SQLRequest(sql: sql, adapter: adapter).fetchSet(db), sql: sql) } } @@ -337,7 +337,7 @@ class FetchableRecordTests: GRDBTestCase { let sql = "SELECT * FROM nonExistingTable" try test(Fetched.fetchSet(db, sql: sql), sql: sql) try test(Fetched.fetchSet(db.makeStatement(sql: sql)), sql: sql) - try test(Fetched.fetchSet(db, SQLRequest(sql: sql)), sql: sql) + try test(Fetched.fetchSet(db, SQLRequest(sql: sql)), sql: sql) try test(SQLRequest(sql: sql).fetchSet(db), sql: sql) } do { @@ -345,7 +345,7 @@ class FetchableRecordTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Fetched.fetchSet(db, sql: sql, adapter: adapter), sql: sql) try test(Fetched.fetchSet(db.makeStatement(sql: sql), adapter: adapter), sql: sql) - try test(Fetched.fetchSet(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(Fetched.fetchSet(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) try test(SQLRequest(sql: sql, adapter: adapter).fetchSet(db), sql: sql) } } @@ -363,7 +363,7 @@ class FetchableRecordTests: GRDBTestCase { let statement = try db.makeStatement(sql: sql) try test(Fetched.fetchOne(db, sql: sql)) try test(Fetched.fetchOne(statement)) - try test(Fetched.fetchOne(db, SQLRequest(sql: sql))) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql))) try test(SQLRequest(sql: sql).fetchOne(db)) } do { @@ -372,7 +372,7 @@ class FetchableRecordTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Fetched.fetchOne(db, sql: sql, adapter: adapter)) try test(Fetched.fetchOne(statement, adapter: adapter)) - try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter))) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter))) try test(SQLRequest(sql: sql, adapter: adapter).fetchOne(db)) } } @@ -386,7 +386,7 @@ class FetchableRecordTests: GRDBTestCase { let statement = try db.makeStatement(sql: sql) try test(Fetched.fetchOne(db, sql: sql)) try test(Fetched.fetchOne(statement)) - try test(Fetched.fetchOne(db, SQLRequest(sql: sql))) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql))) try test(SQLRequest(sql: sql).fetchOne(db)) } do { @@ -395,7 +395,7 @@ class FetchableRecordTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Fetched.fetchOne(db, sql: sql, adapter: adapter)) try test(Fetched.fetchOne(statement, adapter: adapter)) - try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter))) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter))) try test(SQLRequest(sql: sql, adapter: adapter).fetchOne(db)) } } @@ -434,7 +434,7 @@ class FetchableRecordTests: GRDBTestCase { let sql = "SELECT throw()" try test(Fetched.fetchOne(db, sql: sql), sql: sql) try test(Fetched.fetchOne(db.makeStatement(sql: sql)), sql: sql) - try test(Fetched.fetchOne(db, SQLRequest(sql: sql)), sql: sql) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql)), sql: sql) try test(SQLRequest(sql: sql).fetchOne(db), sql: sql) } do { @@ -442,7 +442,7 @@ class FetchableRecordTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Fetched.fetchOne(db, sql: sql, adapter: adapter), sql: sql) try test(Fetched.fetchOne(db.makeStatement(sql: sql), adapter: adapter), sql: sql) - try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) try test(SQLRequest(sql: sql, adapter: adapter).fetchOne(db), sql: sql) } } @@ -466,7 +466,7 @@ class FetchableRecordTests: GRDBTestCase { let sql = "SELECT * FROM nonExistingTable" try test(Fetched.fetchOne(db, sql: sql), sql: sql) try test(Fetched.fetchOne(db.makeStatement(sql: sql)), sql: sql) - try test(Fetched.fetchOne(db, SQLRequest(sql: sql)), sql: sql) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql)), sql: sql) try test(SQLRequest(sql: sql).fetchOne(db), sql: sql) } do { @@ -474,7 +474,7 @@ class FetchableRecordTests: GRDBTestCase { let adapter = SuffixRowAdapter(fromIndex: 1) try test(Fetched.fetchOne(db, sql: sql, adapter: adapter), sql: sql) try test(Fetched.fetchOne(db.makeStatement(sql: sql), adapter: adapter), sql: sql) - try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) + try test(Fetched.fetchOne(db, SQLRequest(sql: sql, adapter: adapter)), sql: sql) try test(SQLRequest(sql: sql, adapter: adapter).fetchOne(db), sql: sql) } } From f36f4aaf7449e993536bee8ddc1e93e6a069982c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 21 Aug 2021 12:44:14 +0200 Subject: [PATCH 02/19] Deprecate count(_ counted: SQLSelectable) --- GRDB/QueryInterface/SQL/SQLFunctions.swift | 12 +++++++++++- GRDB/QueryInterface/SQL/SQLSelection.swift | 3 +-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/GRDB/QueryInterface/SQL/SQLFunctions.swift b/GRDB/QueryInterface/SQL/SQLFunctions.swift index ddd05786f..3d35294a8 100644 --- a/GRDB/QueryInterface/SQL/SQLFunctions.swift +++ b/GRDB/QueryInterface/SQL/SQLFunctions.swift @@ -22,15 +22,25 @@ public func average(_ value: SQLSpecificExpressible) -> SQLExpression { // MARK: - COUNT(...) -// TODO: deprecate, replace with count(expression) /// Returns an expression that evaluates the `COUNT` SQL function. /// /// // COUNT(email) /// count(Column("email")) +/// +/// :nodoc: +@available(*, deprecated) public func count(_ counted: SQLSelectable) -> SQLExpression { counted.sqlSelection.countExpression } +/// Returns an expression that evaluates the `COUNT` SQL function. +/// +/// // COUNT(email) +/// count(Column("email")) +public func count(_ counted: SQLSpecificExpressible) -> SQLExpression { + .count(counted.sqlExpression) +} + // MARK: - COUNT(DISTINCT ...) diff --git a/GRDB/QueryInterface/SQL/SQLSelection.swift b/GRDB/QueryInterface/SQL/SQLSelection.swift index 3daf976bf..cd6655582 100644 --- a/GRDB/QueryInterface/SQL/SQLSelection.swift +++ b/GRDB/QueryInterface/SQL/SQLSelection.swift @@ -74,8 +74,7 @@ extension SQLSelection { } } - /// Support for `count(selection)`. - /// TODO: deprecate `count(selection)`, and get rid of this property. + /// TODO: remove when `count(_ counted: SQLSelectable)` is removed. var countExpression: SQLExpression { switch impl { case .allColumns: From 665770c50ceba957a0a053c2537d92ffa36dbaba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 21 Aug 2021 13:14:54 +0200 Subject: [PATCH 03/19] Remove all ABI annotations --- GRDB/Core/Cursor.swift | 2 - GRDB/Core/Database+Statements.swift | 3 -- GRDB/Core/Database.swift | 1 - GRDB/Core/DatabaseError.swift | 1 - GRDB/Core/DatabaseValue.swift | 4 -- GRDB/Core/DatabaseValueConvertible.swift | 27 +++++------- GRDB/Core/Row.swift | 42 ++++--------------- GRDB/Core/RowDecodingError.swift | 12 ------ GRDB/Core/Statement.swift | 22 ++++------ GRDB/Core/StatementAuthorizer.swift | 1 - GRDB/Core/StatementColumnConvertible.swift | 26 +++++------- GRDB/Core/Support/Foundation/Data.swift | 7 ---- GRDB/Core/Support/Foundation/Date.swift | 2 - .../Support/Foundation/SQLiteDateParser.swift | 6 --- GRDB/Core/Support/Foundation/UUID.swift | 1 - ...aseValueConvertible+RawRepresentable.swift | 2 - .../StandardLibrary/StandardLibrary.swift | 42 ------------------- .../Request/Association/Association.swift | 2 - GRDB/QueryInterface/SQL/SQLRelation.swift | 3 -- GRDB/Record/EncodableRecord+Encodable.swift | 4 -- GRDB/Record/EncodableRecord.swift | 4 +- GRDB/Record/FetchableRecord+Decodable.swift | 9 ---- GRDB/Record/FetchableRecord.swift | 11 +++-- GRDB/Record/PersistableRecord.swift | 19 +-------- GRDB/Utils/OrderedDictionary.swift | 18 ++------ GRDB/Utils/Refinable.swift | 1 - GRDB/Utils/Utils.swift | 11 +---- 27 files changed, 47 insertions(+), 236 deletions(-) diff --git a/GRDB/Core/Cursor.swift b/GRDB/Core/Cursor.swift index 20219c60c..ec5ecdc3a 100644 --- a/GRDB/Core/Cursor.swift +++ b/GRDB/Core/Cursor.swift @@ -19,7 +19,6 @@ extension RangeReplaceableCollection { /// let strings = try Array(cursor) /// /// - parameter cursor: The cursor whose elements feed the collection. - @inlinable public init(_ cursor: C) throws where C.Element == Element { self.init() while let element = try cursor.next() { @@ -36,7 +35,6 @@ extension RangeReplaceableCollection { /// - parameter cursor: The cursor whose elements feed the collection. /// - parameter minimumCapacity: Prepares the returned collection to store /// the specified number of elements. - @inlinable public init(_ cursor: C, minimumCapacity: Int) throws where C.Element == Element { self.init() reserveCapacity(minimumCapacity) diff --git a/GRDB/Core/Database+Statements.swift b/GRDB/Core/Database+Statements.swift index d1d517617..c38870d69 100644 --- a/GRDB/Core/Database+Statements.swift +++ b/GRDB/Core/Database+Statements.swift @@ -588,7 +588,6 @@ extension Database { /// Returns the authorizer that should be used during statement execution /// (this allows preventing the truncate optimization when there exists a /// transaction observer for row deletion). - @usableFromInline func statementWillExecute(_ statement: Statement) throws -> StatementAuthorizer? { // Two things must prevent the statement from executing: aborted // transactions, and database suspension. @@ -604,7 +603,6 @@ extension Database { /// May throw a cancelled commit error, if a transaction observer cancels /// an empty transaction. - @usableFromInline func statementDidExecute(_ statement: Statement) throws { if statement.invalidatesDatabaseSchemaCache { clearSchemaCache() @@ -614,7 +612,6 @@ extension Database { } /// Always throws an error - @usableFromInline func statementDidFail(_ statement: Statement, withResultCode resultCode: Int32) throws -> Never { // Failed statements can not be reused, because sqlite3_reset won't // be able to restore the statement to its initial state: diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index 9a607d73d..953089776 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -6,7 +6,6 @@ public typealias SQLiteConnection = OpaquePointer /// A raw SQLite function argument. typealias SQLiteValue = OpaquePointer -@usableFromInline let SQLITE_TRANSIENT = unsafeBitCast(OpaquePointer(bitPattern: -1), to: sqlite3_destructor_type.self) /// A Database connection. diff --git a/GRDB/Core/DatabaseError.swift b/GRDB/Core/DatabaseError.swift index 9fda1eb42..d492e55dd 100644 --- a/GRDB/Core/DatabaseError.swift +++ b/GRDB/Core/DatabaseError.swift @@ -248,7 +248,6 @@ public struct DatabaseError: Error, CustomStringConvertible, CustomNSError { /// /// This initializer is not public because library user is not supposed to /// be exposed to raw result codes. - @usableFromInline init(resultCode: CInt, message: String? = nil, sql: String? = nil, arguments: StatementArguments? = nil) { self.init(resultCode: ResultCode(rawValue: resultCode), message: message, sql: sql, arguments: arguments) } diff --git a/GRDB/Core/DatabaseValue.swift b/GRDB/Core/DatabaseValue.swift index 65397b29c..80d147c59 100644 --- a/GRDB/Core/DatabaseValue.swift +++ b/GRDB/Core/DatabaseValue.swift @@ -86,7 +86,6 @@ public struct DatabaseValue: Hashable, CustomStringConvertible, DatabaseValueCon // MARK: - Not Public - @inlinable init(storage: Storage) { self.storage = storage } @@ -116,7 +115,6 @@ public struct DatabaseValue: Hashable, CustomStringConvertible, DatabaseValueCon } /// Returns a DatabaseValue initialized from a raw SQLite statement pointer. - @usableFromInline init(sqliteStatement: SQLiteStatement, index: Int32) { switch sqlite3_column_type(sqliteStatement, index) { case SQLITE_NULL: @@ -142,7 +140,6 @@ public struct DatabaseValue: Hashable, CustomStringConvertible, DatabaseValueCon } extension DatabaseValue: StatementBinding { - @inlinable public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt { switch storage { case .null: @@ -221,7 +218,6 @@ extension DatabaseValue { // DatabaseValueConvertible extension DatabaseValue { /// Returns self - @inlinable public var databaseValue: DatabaseValue { self } diff --git a/GRDB/Core/DatabaseValueConvertible.swift b/GRDB/Core/DatabaseValueConvertible.swift index 80f107a47..8ff8bd82b 100644 --- a/GRDB/Core/DatabaseValueConvertible.swift +++ b/GRDB/Core/DatabaseValueConvertible.swift @@ -27,7 +27,6 @@ extension DatabaseValueConvertible { .databaseValue(databaseValue) } - @inlinable public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt { databaseValue.bind(to: sqliteStatement, at: index) } @@ -48,7 +47,6 @@ extension DatabaseValueConvertible { } } - @usableFromInline static func decode( fromStatement sqliteStatement: SQLiteStatement, atUncheckedIndex index: Int32, @@ -59,7 +57,6 @@ extension DatabaseValueConvertible { return try decode(fromDatabaseValue: dbValue, context: context()) } - @usableFromInline static func decode(fromRow row: Row, atUncheckedIndex index: Int) throws -> Self { if let sqliteStatement = row.sqliteStatement { return try decode( @@ -87,7 +84,6 @@ extension DatabaseValueConvertible { } } - @usableFromInline static func decodeIfPresent( fromStatement sqliteStatement: SQLiteStatement, atUncheckedIndex index: Int32, @@ -104,7 +100,6 @@ extension DatabaseValueConvertible { } } - @usableFromInline static func decodeIfPresent(fromRow row: Row, atUncheckedIndex index: Int) throws -> Self? { if let sqliteStatement = row.sqliteStatement { return try decodeIfPresent( @@ -130,14 +125,14 @@ extension DatabaseValueConvertible { /// } /// } public final class DatabaseValueCursor: Cursor { - @usableFromInline enum _State { + private enum _State { case idle, busy, done, failed } - @usableFromInline let _statement: Statement - @usableFromInline let _sqliteStatement: SQLiteStatement - @usableFromInline let _columnIndex: Int32 - @usableFromInline var _state = _State.idle + private let _statement: Statement + private let _sqliteStatement: SQLiteStatement + private let _columnIndex: Int32 + private var _state = _State.idle init(statement: Statement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws { _statement = statement @@ -163,7 +158,6 @@ public final class DatabaseValueCursor: Cursor try? _statement.reset() } - @inlinable public func next() throws -> Value? { switch _state { case .done: @@ -211,14 +205,14 @@ public final class DatabaseValueCursor: Cursor /// } /// } public final class NullableDatabaseValueCursor: Cursor { - @usableFromInline enum _State { + private enum _State { case idle, busy, done, failed } - @usableFromInline let _statement: Statement - @usableFromInline let _sqliteStatement: SQLiteStatement - @usableFromInline let _columnIndex: Int32 - @usableFromInline var _state = _State.idle + private let _statement: Statement + private let _sqliteStatement: SQLiteStatement + private let _columnIndex: Int32 + private var _state = _State.idle init(statement: Statement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws { _statement = statement @@ -244,7 +238,6 @@ public final class NullableDatabaseValueCursor: try? _statement.reset() } - @inlinable public func next() throws -> Value?? { switch _state { case .done: diff --git a/GRDB/Core/Row.swift b/GRDB/Core/Row.swift index c1d6469ce..f51ab18ba 100644 --- a/GRDB/Core/Row.swift +++ b/GRDB/Core/Row.swift @@ -14,8 +14,8 @@ public final class Row: Equatable, Hashable, RandomAccessCollection, /// /// let rows = try Row.fetchCursor(db, sql: "SELECT ...") /// let players = try Player.fetchAll(db, sql: "SELECT ...") - @usableFromInline let statement: Statement? - @usableFromInline let sqliteStatement: SQLiteStatement? + let statement: Statement? + let sqliteStatement: SQLiteStatement? /// The number of columns in the row. public let count: Int @@ -154,7 +154,6 @@ extension Row { index(forColumn: columnName) != nil } - @usableFromInline func index(forColumn name: String) -> Int? { impl.index(forColumn: name) } @@ -165,8 +164,7 @@ extension Row { // MARK: - Extracting Values /// Fatal errors if index is out of bounds - @inlinable - func checkedIndex(_ index: Int, file: StaticString = #file, line: UInt = #line) -> Int { + private func checkedIndex(_ index: Int, file: StaticString = #file, line: UInt = #line) -> Int { GRDBPrecondition(index >= 0 && index < count, "row index out of range", file: file, line: line) return index } @@ -223,7 +221,6 @@ extension Row { /// If the SQLite value is NULL, the result is nil. Otherwise the SQLite /// value is converted to the requested type `Value`. Should this conversion /// fail, a fatal error is raised. - @inlinable public subscript(_ index: Int) -> Value? { try! decodeIfPresent(Value.self, atIndex: index) } @@ -240,7 +237,6 @@ extension Row { /// This method exists as an optimization opportunity for types that adopt /// StatementColumnConvertible. It *may* trigger SQLite built-in conversions /// (see ). - @inlinable public subscript(_ index: Int) -> Value? { try! decodeIfPresent(Value.self, atIndex: index) } @@ -252,7 +248,6 @@ extension Row { /// /// This method crashes if the fetched SQLite value is NULL, or if the /// SQLite value can not be converted to `Value`. - @inlinable public subscript(_ index: Int) -> Value { try! decode(Value.self, atIndex: index) } @@ -268,7 +263,6 @@ extension Row { /// This method exists as an optimization opportunity for types that adopt /// StatementColumnConvertible. It *may* trigger SQLite built-in conversions /// (see ). - @inlinable public subscript(_ index: Int) -> Value { try! decode(Value.self, atIndex: index) } @@ -302,7 +296,6 @@ extension Row { /// If the column is missing or if the SQLite value is NULL, the result is /// nil. Otherwise the SQLite value is converted to the requested type /// `Value`. Should this conversion fail, a fatal error is raised. - @inlinable public subscript(_ columnName: String) -> Value? { try! decodeIfPresent(Value.self, forKey: columnName) } @@ -319,7 +312,6 @@ extension Row { /// This method exists as an optimization opportunity for types that adopt /// StatementColumnConvertible. It *may* trigger SQLite built-in conversions /// (see ). - @inlinable public subscript(_ columnName: String) -> Value? { try! decodeIfPresent(Value.self, forKey: columnName) } @@ -333,7 +325,6 @@ extension Row { /// /// This method crashes if the fetched SQLite value is NULL, or if the /// SQLite value can not be converted to `Value`. - @inlinable public subscript(_ columnName: String) -> Value { try! decode(Value.self, forKey: columnName) } @@ -351,7 +342,6 @@ extension Row { /// This method exists as an optimization opportunity for types that adopt /// StatementColumnConvertible. It *may* trigger SQLite built-in conversions /// (see ). - @inlinable public subscript(_ columnName: String) -> Value { try! decode(Value.self, forKey: columnName) } @@ -363,7 +353,6 @@ extension Row { /// the same name, the leftmost column is considered. /// /// The result is nil if the row does not contain the column. - @inlinable public subscript(_ column: Column) -> DatabaseValueConvertible? { self[column.name] } @@ -376,7 +365,6 @@ extension Row { /// If the column is missing or if the SQLite value is NULL, the result is /// nil. Otherwise the SQLite value is converted to the requested type /// `Value`. Should this conversion fail, a fatal error is raised. - @inlinable public subscript(_ column: Column) -> Value? { try! decodeIfPresent(Value.self, forKey: column.name) } @@ -393,7 +381,6 @@ extension Row { /// This method exists as an optimization opportunity for types that adopt /// StatementColumnConvertible. It *may* trigger SQLite built-in conversions /// (see ). - @inlinable public subscript(_ column: Column) -> Value? where @@ -412,7 +399,6 @@ extension Row { /// /// This method crashes if the fetched SQLite value is NULL, or if the /// SQLite value can not be converted to `Value`. - @inlinable public subscript(_ column: Column) -> Value { try! decode(Value.self, forKey: column.name) } @@ -430,7 +416,6 @@ extension Row { /// This method exists as an optimization opportunity for types that adopt /// StatementColumnConvertible. It *may* trigger SQLite built-in conversions /// (see ). - @inlinable public subscript(_ column: Column) -> Value where @@ -706,7 +691,6 @@ extension Row { /// If the SQLite value is NULL, the result is nil. Otherwise the SQLite /// value is converted to the requested type `Value`. If the conversion /// fail, a `RowDecodingError` is thrown. - @inlinable func decodeIfPresent( _ type: Value.Type = Value.self, atIndex index: Int) @@ -722,7 +706,6 @@ extension Row { /// /// If the SQLite value is NULL, or if the conversion fails, a /// `RowDecodingError` is thrown. - @inlinable func decode( _ type: Value.Type = Value.self, atIndex index: Int) @@ -739,7 +722,6 @@ extension Row { /// If the column is missing or if the SQLite value is NULL, the result is /// nil. Otherwise the SQLite value is converted to the requested type /// `Value`. If the conversion fails, a `RowDecodingError` is thrown. - @inlinable func decodeIfPresent( _ type: Value.Type = Value.self, forKey columnName: String) @@ -759,7 +741,6 @@ extension Row { /// If the row does not contain the column, or if the SQLite value is NULL, /// or if the SQLite value can not be converted to `Value`, a /// `RowDecodingError` is thrown. - @inlinable func decode( _ type: Value.Type = Value.self, forKey columnName: String) @@ -787,7 +768,6 @@ extension Row { /// This method exists as an optimization opportunity for types that adopt /// StatementColumnConvertible. It *may* trigger SQLite built-in conversions /// (see ). - @inlinable func decodeIfPresent( _ type: Value.Type = Value.self, atIndex index: Int) @@ -807,7 +787,6 @@ extension Row { /// This method exists as an optimization opportunity for types that adopt /// StatementColumnConvertible. It *may* trigger SQLite built-in conversions /// (see ). - @inlinable func decode( _ type: Value.Type = Value.self, atIndex index: Int) @@ -828,7 +807,6 @@ extension Row { /// This method exists as an optimization opportunity for types that adopt /// StatementColumnConvertible. It *may* trigger SQLite built-in conversions /// (see ). - @inlinable func decodeIfPresent( _ type: Value.Type = Value.self, forKey columnName: String) @@ -852,7 +830,6 @@ extension Row { /// This method exists as an optimization opportunity for types that adopt /// StatementColumnConvertible. It *may* trigger SQLite built-in conversions /// (see ). - @inlinable func decode( _ type: Value.Type = Value.self, forKey columnName: String) @@ -865,7 +842,6 @@ extension Row { } // Support for fast decoding in scoped rows - @usableFromInline func fastDecode( _ type: Value.Type, atUncheckedIndex index: Int) @@ -875,7 +851,6 @@ extension Row { } // Support for fast decoding in scoped rows - @usableFromInline func fastDecodeIfPresent( _ type: Value.Type, atUncheckedIndex index: Int) @@ -953,13 +928,11 @@ extension Row { } // Support for fast decoding in scoped rows - @usableFromInline func fastDecodeDataNoCopy(atUncheckedIndex index: Int) throws -> Data { try impl.fastDecodeDataNoCopy(atUncheckedIndex: index) } // Support for fast decoding in scoped rows - @usableFromInline func fastDecodeDataNoCopyIfPresent(atUncheckedIndex index: Int) throws -> Data? { try impl.fastDecodeDataNoCopyIfPresent(atUncheckedIndex: index) } @@ -1189,15 +1162,15 @@ extension Row { /// let rows: RowCursor = try Row.fetchCursor(db, sql: "SELECT * FROM player") /// } public final class RowCursor: Cursor { - @usableFromInline enum _State { + private enum _State { case idle, busy, done, failed } /// The statement iterated by this cursor public let statement: Statement - @usableFromInline let _sqliteStatement: SQLiteStatement - @usableFromInline let _row: Row // Reused for performance - @usableFromInline var _state = _State.idle + private let _sqliteStatement: SQLiteStatement + private let _row: Row // Reused for performance + private var _state = _State.idle init(statement: Statement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws { self.statement = statement @@ -1218,7 +1191,6 @@ public final class RowCursor: Cursor { try? statement.reset() } - @inlinable public func next() throws -> Row? { switch _state { case .done: diff --git a/GRDB/Core/RowDecodingError.swift b/GRDB/Core/RowDecodingError.swift index a0c0182f6..fc3bf1e08 100644 --- a/GRDB/Core/RowDecodingError.swift +++ b/GRDB/Core/RowDecodingError.swift @@ -1,5 +1,4 @@ /// A key that is used to decode a value in a row -@usableFromInline enum RowKey: Hashable { /// A column name case columnName(String) @@ -15,12 +14,9 @@ enum RowKey: Hashable { } /// A decoding error -@usableFromInline enum RowDecodingError: Error { - @usableFromInline struct Context: CustomDebugStringConvertible { /// A description of what went wrong, for debugging purposes. - @usableFromInline let debugDescription: String /// The row that could not be decoded @@ -35,7 +31,6 @@ enum RowDecodingError: Error { /// The SQL query arguments let statementArguments: StatementArguments? - @usableFromInline init(decodingContext: RowDecodingContext, debugDescription: String) { self.debugDescription = debugDescription self.row = decodingContext.row @@ -73,7 +68,6 @@ enum RowDecodingError: Error { /// Convenience method that builds the /// `could not decode from database value ` error message. - @usableFromInline static func valueMismatch( _ type: Any.Type, sqliteStatement: SQLiteStatement, @@ -89,7 +83,6 @@ enum RowDecodingError: Error { /// Convenience method that builds the /// `could not decode from database value ` error message. - @usableFromInline static func valueMismatch( _ type: Any.Type, statement: Statement, @@ -104,7 +97,6 @@ enum RowDecodingError: Error { /// Convenience method that builds the `column not found: ` /// error message. - @usableFromInline static func columnNotFound(_ columnName: String, context: RowDecodingContext) -> Self { keyNotFound( .columnName(columnName), @@ -114,7 +106,6 @@ enum RowDecodingError: Error { } } -@usableFromInline struct RowDecodingContext { /// The row that is decoded let row: Row @@ -127,7 +118,6 @@ struct RowDecodingContext { /// The SQL query arguments let statementArguments: StatementArguments? - @usableFromInline init(row: Row, key: RowKey? = nil) { if let statement = row.statement { self.key = key @@ -148,7 +138,6 @@ struct RowDecodingContext { } /// Convenience initializer - @usableFromInline init(statement: Statement, index: Int) { self.key = .columnIndex(index) self.row = Row(copiedFromSQLiteStatement: statement.sqliteStatement, statement: statement) @@ -158,7 +147,6 @@ struct RowDecodingContext { } extension RowDecodingError: CustomStringConvertible { - @usableFromInline var description: String { let context = self.context let row = context.row diff --git a/GRDB/Core/Statement.swift b/GRDB/Core/Statement.swift index 23defd7d9..5946ce420 100644 --- a/GRDB/Core/Statement.swift +++ b/GRDB/Core/Statement.swift @@ -58,7 +58,6 @@ public final class Statement { sqlite3_stmt_readonly(sqliteStatement) != 0 } - @usableFromInline unowned let database: Database /// Cache for index(ofColumn:). Keys are lowercase. @@ -129,7 +128,6 @@ public final class Statement { sqlite3_finalize(sqliteStatement) } - @usableFromInline final func reset() throws { SchedulingWatchdog.preconditionValidQueue(database) let code = sqlite3_reset(sqliteStatement) @@ -141,11 +139,9 @@ public final class Statement { // MARK: Arguments - @usableFromInline - var argumentsNeedValidation = true + private var argumentsNeedValidation = true - @usableFromInline - var _arguments = StatementArguments() + private var _arguments = StatementArguments() lazy var sqliteArgumentCount: Int = { Int(sqlite3_bind_parameter_count(self.sqliteStatement)) @@ -260,7 +256,6 @@ public final class Statement { } // 1-based index - @inlinable func bind(_ value: T, at index: CInt) { let code = value.bind(to: sqliteStatement, at: index) @@ -272,7 +267,6 @@ public final class Statement { } // Don't make this one public unless we keep the arguments property in sync. - @usableFromInline func clearBindings() { // It looks like sqlite3_clear_bindings() does not access the file system. // This function call should thus succeed, unless a GRDB bug: there is @@ -340,13 +334,13 @@ extension Statement { /// try cursor.next() /// } final class StatementCursor: Cursor { - @usableFromInline enum _State { + private enum _State { case idle, busy, done, failed } - let _statement: Statement - let _sqliteStatement: SQLiteStatement - var _state = _State.idle + /* private, internal for testability */ let _statement: Statement + private let _sqliteStatement: SQLiteStatement + private var _state = _State.idle // Use Statement.makeCursor() instead init(statement: Statement, arguments: StatementArguments? = nil) throws { @@ -368,7 +362,6 @@ final class StatementCursor: Cursor { } /// :nodoc: - @inlinable func next() throws -> Void? { switch _state { case .done: @@ -592,8 +585,7 @@ public struct StatementArguments: CustomStringConvertible, Equatable, self.init(values) } - @usableFromInline - mutating func set(databaseValues: [DatabaseValue]) { + private mutating func set(databaseValues: [DatabaseValue]) { self.values = databaseValues namedValues.removeAll(keepingCapacity: true) } diff --git a/GRDB/Core/StatementAuthorizer.swift b/GRDB/Core/StatementAuthorizer.swift index 44fea582c..a19b83ce9 100644 --- a/GRDB/Core/StatementAuthorizer.swift +++ b/GRDB/Core/StatementAuthorizer.swift @@ -3,7 +3,6 @@ import Glibc #endif /// A protocol around sqlite3_set_authorizer -@usableFromInline protocol StatementAuthorizer: AnyObject { func authorize( _ actionCode: Int32, diff --git a/GRDB/Core/StatementColumnConvertible.swift b/GRDB/Core/StatementColumnConvertible.swift index 278f5e239..67481a78e 100644 --- a/GRDB/Core/StatementColumnConvertible.swift +++ b/GRDB/Core/StatementColumnConvertible.swift @@ -45,7 +45,6 @@ public protocol StatementColumnConvertible { // MARK: - Conversions extension DatabaseValueConvertible where Self: StatementColumnConvertible { - @inlinable static func fastDecode( fromStatement sqliteStatement: SQLiteStatement, atUncheckedIndex index: Int32, @@ -64,7 +63,6 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { return value } - @inlinable static func fastDecode( fromRow row: Row, atUncheckedIndex index: Int) @@ -80,7 +78,6 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { return try row.fastDecode(Self.self, atUncheckedIndex: index) } - @inlinable static func fastDecodeIfPresent( fromStatement sqliteStatement: SQLiteStatement, atUncheckedIndex index: Int32, @@ -100,7 +97,6 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { return value } - @inlinable static func fastDecodeIfPresent( fromRow row: Row, atUncheckedIndex index: Int) @@ -129,14 +125,14 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { /// } /// } public final class FastDatabaseValueCursor : Cursor { - @usableFromInline enum _State { + private enum _State { case idle, busy, done, failed } - @usableFromInline let _statement: Statement - @usableFromInline let _columnIndex: Int32 - @usableFromInline let _sqliteStatement: SQLiteStatement - @usableFromInline var _state = _State.idle + private let _statement: Statement + private let _columnIndex: Int32 + private let _sqliteStatement: SQLiteStatement + private var _state = _State.idle init(statement: Statement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws { _statement = statement @@ -162,7 +158,6 @@ public final class FastDatabaseValueCursor Value? { switch _state { case .done: @@ -213,14 +208,14 @@ public final class FastDatabaseValueCursor: Cursor where Value: DatabaseValueConvertible & StatementColumnConvertible { - @usableFromInline enum _State { + private enum _State { case idle, busy, done, failed } - @usableFromInline let _statement: Statement - @usableFromInline let _columnIndex: Int32 - @usableFromInline let _sqliteStatement: SQLiteStatement - @usableFromInline var _state = _State.idle + private let _statement: Statement + private let _columnIndex: Int32 + private let _sqliteStatement: SQLiteStatement + private var _state = _State.idle init(statement: Statement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws { _statement = statement @@ -246,7 +241,6 @@ where Value: DatabaseValueConvertible & StatementColumnConvertible try? _statement.reset() } - @inlinable public func next() throws -> Value?? { switch _state { case .done: diff --git a/GRDB/Core/Support/Foundation/Data.swift b/GRDB/Core/Support/Foundation/Data.swift index eb37b2612..ec5d1c1ad 100644 --- a/GRDB/Core/Support/Foundation/Data.swift +++ b/GRDB/Core/Support/Foundation/Data.swift @@ -2,7 +2,6 @@ import Foundation /// Data is convertible to and from DatabaseValue. extension Data: DatabaseValueConvertible, StatementColumnConvertible { - @inlinable public init(sqliteStatement: SQLiteStatement, index: Int32) { if let bytes = sqlite3_column_blob(sqliteStatement, index) { let count = Int(sqlite3_column_bytes(sqliteStatement, index)) @@ -13,7 +12,6 @@ extension Data: DatabaseValueConvertible, StatementColumnConvertible { } /// Returns a value that can be stored in the database. - @inlinable public var databaseValue: DatabaseValue { DatabaseValue(storage: .blob(self)) } @@ -33,7 +31,6 @@ extension Data: DatabaseValueConvertible, StatementColumnConvertible { } } - @inlinable public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt { withUnsafeBytes { sqlite3_bind_blob(sqliteStatement, index, $0.baseAddress, Int32($0.count), SQLITE_TRANSIENT) @@ -44,7 +41,6 @@ extension Data: DatabaseValueConvertible, StatementColumnConvertible { // MARK: - Conversions extension Data { - @inlinable static func fastDecodeNoCopy( fromStatement sqliteStatement: SQLiteStatement, atUncheckedIndex index: Int32, @@ -65,7 +61,6 @@ extension Data { return Data(bytesNoCopy: UnsafeMutableRawPointer(mutating: bytes), count: count, deallocator: .none) } - @inlinable static func fastDecodeNoCopy( fromRow row: Row, atUncheckedIndex index: Int) @@ -81,7 +76,6 @@ extension Data { return try row.fastDecodeDataNoCopy(atUncheckedIndex: index) } - @inlinable static func fastDecodeNoCopyIfPresent( fromStatement sqliteStatement: SQLiteStatement, atUncheckedIndex index: Int32, @@ -98,7 +92,6 @@ extension Data { return Data(bytesNoCopy: UnsafeMutableRawPointer(mutating: bytes), count: count, deallocator: .none) } - @inlinable static func fastDecodeNoCopyIfPresent( fromRow row: Row, atUncheckedIndex index: Int) diff --git a/GRDB/Core/Support/Foundation/Date.swift b/GRDB/Core/Support/Foundation/Date.swift index 929302d3a..d97052197 100644 --- a/GRDB/Core/Support/Foundation/Date.swift +++ b/GRDB/Core/Support/Foundation/Date.swift @@ -58,7 +58,6 @@ extension Date: DatabaseValueConvertible { return nil } - @usableFromInline init?(databaseDateComponents: DatabaseDateComponents) { guard databaseDateComponents.format.hasYMDComponents else { // Refuse to turn hours without any date information into Date: @@ -118,7 +117,6 @@ extension Date: StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. - @inlinable public init?(sqliteStatement: SQLiteStatement, index: Int32) { switch sqlite3_column_type(sqliteStatement, index) { case SQLITE_INTEGER, SQLITE_FLOAT: diff --git a/GRDB/Core/Support/Foundation/SQLiteDateParser.swift b/GRDB/Core/Support/Foundation/SQLiteDateParser.swift index 8ff5be601..b98f288b3 100644 --- a/GRDB/Core/Support/Foundation/SQLiteDateParser.swift +++ b/GRDB/Core/Support/Foundation/SQLiteDateParser.swift @@ -161,13 +161,11 @@ final class SQLiteDateParser { var cString: UnsafePointer var length: Int - @inline(__always) private mutating func shift() { cString += 1 length -= 1 } - @inline(__always) mutating func parse(_ scalar: Unicode.Scalar) -> Bool { guard length > 0, cString[0] == UInt8(ascii: scalar) else { return false @@ -176,7 +174,6 @@ final class SQLiteDateParser { return true } - @inline(__always) mutating func parseDigit() -> Int? { guard length > 0 else { return nil @@ -190,7 +187,6 @@ final class SQLiteDateParser { return Int(digit) } - @inline(__always) mutating func parseDigit(into number: inout Int) -> Bool { guard let digit = parseDigit() else { return false @@ -199,7 +195,6 @@ final class SQLiteDateParser { return true } - @inline(__always) mutating func parseNNNN() -> Int? { var number = 0 guard parseDigit(into: &number) @@ -213,7 +208,6 @@ final class SQLiteDateParser { return number } - @inline(__always) mutating func parseNN() -> Int? { var number = 0 guard parseDigit(into: &number) diff --git a/GRDB/Core/Support/Foundation/UUID.swift b/GRDB/Core/Support/Foundation/UUID.swift index 1dac7425e..0368b8817 100644 --- a/GRDB/Core/Support/Foundation/UUID.swift +++ b/GRDB/Core/Support/Foundation/UUID.swift @@ -49,7 +49,6 @@ extension UUID: DatabaseValueConvertible { } extension UUID: StatementColumnConvertible { - @inlinable public init?(sqliteStatement: SQLiteStatement, index: Int32) { switch sqlite3_column_type(sqliteStatement, index) { case SQLITE_TEXT: diff --git a/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+RawRepresentable.swift b/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+RawRepresentable.swift index 947b9a160..b49824f5e 100644 --- a/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+RawRepresentable.swift +++ b/GRDB/Core/Support/StandardLibrary/DatabaseValueConvertible+RawRepresentable.swift @@ -18,7 +18,6 @@ extension SQLExpressible where Self: RawRepresentable, Self.RawValue: SQLExpress } extension StatementBinding where Self: RawRepresentable, Self.RawValue: StatementBinding { - @inlinable public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt { rawValue.bind(to: sqliteStatement, at: index) } @@ -38,7 +37,6 @@ extension StatementBinding where Self: RawRepresentable, Self.RawValue: Statemen /// // adopt DatabaseValueConvertible: /// extension Color: DatabaseValueConvertible { } extension DatabaseValueConvertible where Self: RawRepresentable, Self.RawValue: DatabaseValueConvertible { - @inlinable public var databaseValue: DatabaseValue { rawValue.databaseValue } diff --git a/GRDB/Core/Support/StandardLibrary/StandardLibrary.swift b/GRDB/Core/Support/StandardLibrary/StandardLibrary.swift index 3a0aab73f..bbad16951 100644 --- a/GRDB/Core/Support/StandardLibrary/StandardLibrary.swift +++ b/GRDB/Core/Support/StandardLibrary/StandardLibrary.swift @@ -8,13 +8,11 @@ extension Bool: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. - @inlinable public init(sqliteStatement: SQLiteStatement, index: Int32) { self = sqlite3_column_int64(sqliteStatement, index) != 0 } /// Returns a value that can be stored in the database. - @inlinable public var databaseValue: DatabaseValue { (self ? 1 : 0).databaseValue } @@ -87,7 +85,6 @@ extension Bool: DatabaseValueConvertible, StatementColumnConvertible { } } - @inlinable public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt { sqlite3_bind_int64(sqliteStatement, index, self ? 1 : 0) } @@ -101,7 +98,6 @@ extension Int: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. - @inlinable public init?(sqliteStatement: SQLiteStatement, index: Int32) { let int64 = sqlite3_column_int64(sqliteStatement, index) guard let v = Int(exactly: int64) else { return nil } @@ -109,7 +105,6 @@ extension Int: DatabaseValueConvertible, StatementColumnConvertible { } /// Returns a value that can be stored in the database. - @inlinable public var databaseValue: DatabaseValue { Int64(self).databaseValue } @@ -119,7 +114,6 @@ extension Int: DatabaseValueConvertible, StatementColumnConvertible { Int64.fromDatabaseValue(dbValue).flatMap { Int(exactly: $0) } } - @inlinable public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt { sqlite3_bind_int64(sqliteStatement, index, Int64(self)) } @@ -133,7 +127,6 @@ extension Int8: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. - @inlinable public init?(sqliteStatement: SQLiteStatement, index: Int32) { let int64 = sqlite3_column_int64(sqliteStatement, index) guard let v = Int8(exactly: int64) else { return nil } @@ -141,7 +134,6 @@ extension Int8: DatabaseValueConvertible, StatementColumnConvertible { } /// Returns a value that can be stored in the database. - @inlinable public var databaseValue: DatabaseValue { Int64(self).databaseValue } @@ -151,7 +143,6 @@ extension Int8: DatabaseValueConvertible, StatementColumnConvertible { Int64.fromDatabaseValue(dbValue).flatMap { Int8(exactly: $0) } } - @inlinable public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt { sqlite3_bind_int64(sqliteStatement, index, Int64(self)) } @@ -165,7 +156,6 @@ extension Int16: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. - @inlinable public init?(sqliteStatement: SQLiteStatement, index: Int32) { let int64 = sqlite3_column_int64(sqliteStatement, index) guard let v = Int16(exactly: int64) else { return nil } @@ -173,7 +163,6 @@ extension Int16: DatabaseValueConvertible, StatementColumnConvertible { } /// Returns a value that can be stored in the database. - @inlinable public var databaseValue: DatabaseValue { Int64(self).databaseValue } @@ -183,7 +172,6 @@ extension Int16: DatabaseValueConvertible, StatementColumnConvertible { Int64.fromDatabaseValue(dbValue).flatMap { Int16(exactly: $0) } } - @inlinable public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt { sqlite3_bind_int64(sqliteStatement, index, Int64(self)) } @@ -197,7 +185,6 @@ extension Int32: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. - @inlinable public init?(sqliteStatement: SQLiteStatement, index: Int32) { let int64 = sqlite3_column_int64(sqliteStatement, index) guard let v = Int32(exactly: int64) else { return nil } @@ -205,7 +192,6 @@ extension Int32: DatabaseValueConvertible, StatementColumnConvertible { } /// Returns a value that can be stored in the database. - @inlinable public var databaseValue: DatabaseValue { Int64(self).databaseValue } @@ -215,7 +201,6 @@ extension Int32: DatabaseValueConvertible, StatementColumnConvertible { Int64.fromDatabaseValue(dbValue).flatMap { Int32(exactly: $0) } } - @inlinable public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt { sqlite3_bind_int64(sqliteStatement, index, Int64(self)) } @@ -229,13 +214,11 @@ extension Int64: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. - @inlinable public init(sqliteStatement: SQLiteStatement, index: Int32) { self = sqlite3_column_int64(sqliteStatement, index) } /// Returns a value that can be stored in the database. - @inlinable public var databaseValue: DatabaseValue { DatabaseValue(storage: .int64(self)) } @@ -254,7 +237,6 @@ extension Int64: DatabaseValueConvertible, StatementColumnConvertible { } } - @inlinable public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt { sqlite3_bind_int64(sqliteStatement, index, self) } @@ -268,7 +250,6 @@ extension UInt: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. - @inlinable public init?(sqliteStatement: SQLiteStatement, index: Int32) { let int64 = sqlite3_column_int64(sqliteStatement, index) guard let v = UInt(exactly: int64) else { return nil } @@ -276,7 +257,6 @@ extension UInt: DatabaseValueConvertible, StatementColumnConvertible { } /// Returns a value that can be stored in the database. - @inlinable public var databaseValue: DatabaseValue { Int64(self).databaseValue } @@ -286,7 +266,6 @@ extension UInt: DatabaseValueConvertible, StatementColumnConvertible { Int64.fromDatabaseValue(dbValue).flatMap { UInt(exactly: $0) } } - @inlinable public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt { sqlite3_bind_int64(sqliteStatement, index, Int64(self)) } @@ -300,7 +279,6 @@ extension UInt8: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. - @inlinable public init?(sqliteStatement: SQLiteStatement, index: Int32) { let int64 = sqlite3_column_int64(sqliteStatement, index) guard let v = UInt8(exactly: int64) else { return nil } @@ -308,7 +286,6 @@ extension UInt8: DatabaseValueConvertible, StatementColumnConvertible { } /// Returns a value that can be stored in the database. - @inlinable public var databaseValue: DatabaseValue { Int64(self).databaseValue } @@ -318,7 +295,6 @@ extension UInt8: DatabaseValueConvertible, StatementColumnConvertible { Int64.fromDatabaseValue(dbValue).flatMap { UInt8(exactly: $0) } } - @inlinable public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt { sqlite3_bind_int64(sqliteStatement, index, Int64(self)) } @@ -332,7 +308,6 @@ extension UInt16: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. - @inlinable public init?(sqliteStatement: SQLiteStatement, index: Int32) { let int64 = sqlite3_column_int64(sqliteStatement, index) guard let v = UInt16(exactly: int64) else { return nil } @@ -340,7 +315,6 @@ extension UInt16: DatabaseValueConvertible, StatementColumnConvertible { } /// Returns a value that can be stored in the database. - @inlinable public var databaseValue: DatabaseValue { Int64(self).databaseValue } @@ -350,7 +324,6 @@ extension UInt16: DatabaseValueConvertible, StatementColumnConvertible { Int64.fromDatabaseValue(dbValue).flatMap { UInt16(exactly: $0) } } - @inlinable public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt { sqlite3_bind_int64(sqliteStatement, index, Int64(self)) } @@ -364,7 +337,6 @@ extension UInt32: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. - @inlinable public init?(sqliteStatement: SQLiteStatement, index: Int32) { let int64 = sqlite3_column_int64(sqliteStatement, index) guard let v = UInt32(exactly: int64) else { return nil } @@ -372,7 +344,6 @@ extension UInt32: DatabaseValueConvertible, StatementColumnConvertible { } /// Returns a value that can be stored in the database. - @inlinable public var databaseValue: DatabaseValue { Int64(self).databaseValue } @@ -382,7 +353,6 @@ extension UInt32: DatabaseValueConvertible, StatementColumnConvertible { Int64.fromDatabaseValue(dbValue).flatMap { UInt32(exactly: $0) } } - @inlinable public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt { sqlite3_bind_int64(sqliteStatement, index, Int64(self)) } @@ -396,7 +366,6 @@ extension UInt64: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. - @inlinable public init?(sqliteStatement: SQLiteStatement, index: Int32) { let int64 = sqlite3_column_int64(sqliteStatement, index) guard let v = UInt64(exactly: int64) else { return nil } @@ -404,7 +373,6 @@ extension UInt64: DatabaseValueConvertible, StatementColumnConvertible { } /// Returns a value that can be stored in the database. - @inlinable public var databaseValue: DatabaseValue { Int64(self).databaseValue } @@ -414,7 +382,6 @@ extension UInt64: DatabaseValueConvertible, StatementColumnConvertible { Int64.fromDatabaseValue(dbValue).flatMap { UInt64(exactly: $0) } } - @inlinable public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt { sqlite3_bind_int64(sqliteStatement, index, Int64(self)) } @@ -428,13 +395,11 @@ extension Double: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. - @inlinable public init(sqliteStatement: SQLiteStatement, index: Int32) { self = sqlite3_column_double(sqliteStatement, index) } /// Returns a value that can be stored in the database. - @inlinable public var databaseValue: DatabaseValue { DatabaseValue(storage: .double(self)) } @@ -451,7 +416,6 @@ extension Double: DatabaseValueConvertible, StatementColumnConvertible { } } - @inlinable public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt { sqlite3_bind_double(sqliteStatement, index, self) } @@ -465,13 +429,11 @@ extension Float: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. - @inlinable public init(sqliteStatement: SQLiteStatement, index: Int32) { self = Float(sqlite3_column_double(sqliteStatement, index)) } /// Returns a value that can be stored in the database. - @inlinable public var databaseValue: DatabaseValue { Double(self).databaseValue } @@ -488,7 +450,6 @@ extension Float: DatabaseValueConvertible, StatementColumnConvertible { } } - @inlinable public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt { sqlite3_bind_double(sqliteStatement, index, Double(self)) } @@ -502,13 +463,11 @@ extension String: DatabaseValueConvertible, StatementColumnConvertible { /// - parameters: /// - sqliteStatement: A pointer to an SQLite statement. /// - index: The column index. - @inlinable public init(sqliteStatement: SQLiteStatement, index: Int32) { self = String(cString: sqlite3_column_text(sqliteStatement, index)!) } /// Returns a value that can be stored in the database. - @inlinable public var databaseValue: DatabaseValue { DatabaseValue(storage: .string(self)) } @@ -527,7 +486,6 @@ extension String: DatabaseValueConvertible, StatementColumnConvertible { } } - @inlinable public func bind(to sqliteStatement: SQLiteStatement, at index: CInt) -> CInt { sqlite3_bind_text(sqliteStatement, index, self, -1, SQLITE_TRANSIENT) } diff --git a/GRDB/QueryInterface/Request/Association/Association.swift b/GRDB/QueryInterface/Request/Association/Association.swift index c6714f9c9..7ec25bfa7 100644 --- a/GRDB/QueryInterface/Request/Association/Association.swift +++ b/GRDB/QueryInterface/Request/Association/Association.swift @@ -45,7 +45,6 @@ public protocol Association: _Association, DerivableRequest { extension Association { /// Returns self modified with the *update* function. - @inline(__always) func with(_ update: (inout Self) throws -> Void) rethrows -> Self { var result = self try update(&result) @@ -53,7 +52,6 @@ extension Association { } /// Returns self with destination relation modified with the *update* function. - @inline(__always) fileprivate func withDestinationRelation(_ update: (inout SQLRelation) throws -> Void) rethrows -> Self { var result = self try update(&result._sqlAssociation.destination.relation) diff --git a/GRDB/QueryInterface/SQL/SQLRelation.swift b/GRDB/QueryInterface/SQL/SQLRelation.swift index 3be12514e..07f45dd95 100644 --- a/GRDB/QueryInterface/SQL/SQLRelation.swift +++ b/GRDB/QueryInterface/SQL/SQLRelation.swift @@ -965,20 +965,17 @@ protocol ColumnAddressable { struct DummyRow: ColumnAddressable { struct DummyIndex { } func index(forColumn column: String) -> DummyIndex? { DummyIndex() } - @inline(__always) func databaseValue(at index: DummyIndex) -> DatabaseValue { DatabaseValue(storage: .int64(1)) } } /// Row has columns extension Row: ColumnAddressable { - @inline(__always) func databaseValue(at index: Int) -> DatabaseValue { self[index] } } /// PersistenceContainer has columns extension PersistenceContainer: ColumnAddressable { func index(forColumn column: String) -> String? { column } - @inline(__always) func databaseValue(at column: String) -> DatabaseValue { self[caseInsensitive: column]?.databaseValue ?? .null } diff --git a/GRDB/Record/EncodableRecord+Encodable.swift b/GRDB/Record/EncodableRecord+Encodable.swift index e61e57e4e..6fb63e83c 100644 --- a/GRDB/Record/EncodableRecord+Encodable.swift +++ b/GRDB/Record/EncodableRecord+Encodable.swift @@ -120,12 +120,10 @@ private class RecordEncoder: Encoder { } /// Helper methods - @inline(__always) fileprivate func persist(_ value: DatabaseValueConvertible?, forKey key: CodingKey) { _persistenceContainer[key.stringValue] = value } - @inline(__always) fileprivate func encode(_ value: T, forKey key: CodingKey) throws where T: Encodable { if let date = value as? Date { persist(Record.databaseDateEncodingStrategy.encode(date), forKey: key) @@ -236,7 +234,6 @@ private var iso8601Formatter: ISO8601DateFormatter = { }() extension DatabaseDateEncodingStrategy { - @inline(__always) fileprivate func encode(_ date: Date) -> DatabaseValueConvertible? { switch self { case .deferredToDate: @@ -264,7 +261,6 @@ extension DatabaseDateEncodingStrategy { } extension DatabaseUUIDEncodingStrategy { - @inline(__always) fileprivate func encode(_ uuid: UUID) -> DatabaseValueConvertible? { switch self { case .deferredToUUID: diff --git a/GRDB/Record/EncodableRecord.swift b/GRDB/Record/EncodableRecord.swift index 9195b421a..a4926569a 100644 --- a/GRDB/Record/EncodableRecord.swift +++ b/GRDB/Record/EncodableRecord.swift @@ -195,14 +195,13 @@ public struct PersistenceContainer { // fileprivate for Row(_:PersistenceContainer) // The ordering of the OrderedDictionary helps generating always the same // SQL queries, and hit the statement cache. - @usableFromInline var storage: OrderedDictionary + fileprivate var storage: OrderedDictionary /// Accesses the value associated with the given column. /// /// It is undefined behavior to set different values for the same column. /// Column names are case insensitive, so defining both "name" and "NAME" /// is considered undefined behavior. - @inlinable public subscript(_ column: String) -> DatabaseValueConvertible? { get { storage[column] ?? nil } set { storage.updateValue(newValue, forKey: column) } @@ -213,7 +212,6 @@ public struct PersistenceContainer { /// It is undefined behavior to set different values for the same column. /// Column names are case insensitive, so defining both "name" and "NAME" /// is considered undefined behavior. - @inlinable public subscript(_ column: Column) -> DatabaseValueConvertible? { get { self[column.name] } set { self[column.name] = newValue } diff --git a/GRDB/Record/FetchableRecord+Decodable.swift b/GRDB/Record/FetchableRecord+Decodable.swift index ae96ce03e..6859ec594 100644 --- a/GRDB/Record/FetchableRecord+Decodable.swift +++ b/GRDB/Record/FetchableRecord+Decodable.swift @@ -238,7 +238,6 @@ private struct _RowDecoder: Decoder { // Helper methods - @inline(__always) private func decode( _ type: T.Type, fromRow row: Row, @@ -255,7 +254,6 @@ private struct _RowDecoder: Decoder { } } - @inline(__always) private func decode( _ type: T.Type, fromRow row: Row, @@ -404,7 +402,6 @@ private var iso8601Formatter: ISO8601DateFormatter = { }() extension DatabaseDateDecodingStrategy { - @inline(__always) fileprivate func decodeIfPresent(fromRow row: Row, atUncheckedIndex index: Int) throws -> Date? { if let sqliteStatement = row.sqliteStatement { return try decodeIfPresent( @@ -418,7 +415,6 @@ extension DatabaseDateDecodingStrategy { } } - @inline(__always) fileprivate func decode(fromRow row: Row, atUncheckedIndex index: Int) throws -> Date { if let sqliteStatement = row.sqliteStatement { return try decode( @@ -432,7 +428,6 @@ extension DatabaseDateDecodingStrategy { } } - @inline(__always) fileprivate func decode( fromStatement sqliteStatement: SQLiteStatement, atUncheckedIndex index: Int32, @@ -491,7 +486,6 @@ extension DatabaseDateDecodingStrategy { } } - @inline(__always) fileprivate func decodeIfPresent( fromStatement sqliteStatement: SQLiteStatement, atUncheckedIndex index: Int32, @@ -504,7 +498,6 @@ extension DatabaseDateDecodingStrategy { return try decode(fromStatement: sqliteStatement, atUncheckedIndex: index, context: context()) } - @inline(__always) fileprivate func decode( fromDatabaseValue dbValue: DatabaseValue, context: @autoclosure () -> RowDecodingContext) @@ -517,7 +510,6 @@ extension DatabaseDateDecodingStrategy { } } - @inline(__always) fileprivate func decodeIfPresent( fromDatabaseValue dbValue: DatabaseValue, context: @autoclosure () -> RowDecodingContext) @@ -533,7 +525,6 @@ extension DatabaseDateDecodingStrategy { } // Returns nil if decoding fails - @inline(__always) private func dateFromDatabaseValue(_ dbValue: DatabaseValue) -> Date? { switch self { case .deferredToDate: diff --git a/GRDB/Record/FetchableRecord.swift b/GRDB/Record/FetchableRecord.swift index b23ca7ea6..0861bd382 100644 --- a/GRDB/Record/FetchableRecord.swift +++ b/GRDB/Record/FetchableRecord.swift @@ -494,14 +494,14 @@ extension FetchRequest where RowDecoder: FetchableRecord & Hashable { /// let players: RecordCursor = try Player.fetchCursor(db, sql: "SELECT * FROM player") /// } public final class RecordCursor: Cursor { - @usableFromInline enum _State { + private enum _State { case idle, busy, done, failed } - @usableFromInline let _statement: Statement - @usableFromInline let _row: Row // Reused for performance - @usableFromInline let _sqliteStatement: SQLiteStatement - @usableFromInline var _state = _State.idle + private let _statement: Statement + private let _row: Row // Reused for performance + private let _sqliteStatement: SQLiteStatement + private var _state = _State.idle init(statement: Statement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws { _statement = statement @@ -522,7 +522,6 @@ public final class RecordCursor: Cursor { try? _statement.reset() } - @inlinable public func next() throws -> Record? { switch _state { case .done: diff --git a/GRDB/Record/PersistableRecord.swift b/GRDB/Record/PersistableRecord.swift index 782b49fb1..be1f325dc 100644 --- a/GRDB/Record/PersistableRecord.swift +++ b/GRDB/Record/PersistableRecord.swift @@ -1,5 +1,5 @@ extension Database.ConflictResolution { - @usableFromInline var invalidatesLastInsertedRowID: Bool { + var invalidatesLastInsertedRowID: Bool { switch self { case .abort, .fail, .rollback, .replace: return false @@ -350,7 +350,6 @@ extension MutablePersistableRecord { // MARK: - CRUD Internals /// Return a non-nil dictionary if record has a non-null primary key - @usableFromInline func primaryKey(_ db: Database) throws -> [String: DatabaseValue]? { let databaseTableName = type(of: self).databaseTableName let primaryKeyInfo = try db.primaryKey(databaseTableName) @@ -371,7 +370,6 @@ extension MutablePersistableRecord { /// that adopt MutablePersistableRecord can invoke performInsert() in their /// implementation of insert(). They should not provide their own /// implementation of performInsert(). - @inlinable public mutating func performInsert(_ db: Database) throws { let conflictResolutionForInsert = type(of: self).persistenceConflictPolicy.conflictResolutionForInsert let dao = try DAO(db, self) @@ -395,7 +393,6 @@ extension MutablePersistableRecord { /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. /// PersistenceError.recordNotFound is thrown if the primary key does not /// match any row in the database. - @inlinable public func performUpdate(_ db: Database, columns: Set) throws { let dao = try DAO(db, self) guard let statement = try dao.updateStatement( @@ -420,7 +417,6 @@ extension MutablePersistableRecord { /// implementation of performSave(). /// /// This default implementation forwards the job to `update` or `insert`. - @inlinable public mutating func performSave(_ db: Database) throws { // Call self.insert and self.update so that we support classes that // override those methods. @@ -442,7 +438,6 @@ extension MutablePersistableRecord { /// that adopt MutablePersistableRecord can invoke performDelete() in /// their implementation of delete(). They should not provide their own /// implementation of performDelete(). - @inlinable public func performDelete(_ db: Database) throws -> Bool { guard let statement = try DAO(db, self).deleteStatement() else { // Nil primary key @@ -459,7 +454,6 @@ extension MutablePersistableRecord { /// that adopt MutablePersistableRecord can invoke performExists() in /// their implementation of exists(). They should not provide their own /// implementation of performExists(). - @inlinable public func performExists(_ db: Database) throws -> Bool { guard let statement = try DAO(db, self).existsStatement() else { // Nil primary key @@ -602,7 +596,6 @@ extension PersistableRecord { /// that adopt PersistableRecord can invoke performInsert() in their /// implementation of insert(). They should not provide their own /// implementation of performInsert(). - @inlinable public func performInsert(_ db: Database) throws { let conflictResolutionForInsert = type(of: self).persistenceConflictPolicy.conflictResolutionForInsert let dao = try DAO(db, self) @@ -622,7 +615,6 @@ extension PersistableRecord { /// implementation of performSave(). /// /// This default implementation forwards the job to `update` or `insert`. - @inlinable public func performSave(_ db: Database) throws { // Call self.insert and self.update so that we support classes that // override those methods. @@ -651,7 +643,6 @@ extension PersistenceContainer { } /// DAO takes care of PersistableRecord CRUD -@usableFromInline final class DAO { /// The database let db: Database @@ -665,9 +656,8 @@ final class DAO { let databaseTableName: String /// The table primary key info - @usableFromInline let primaryKey: PrimaryKeyInfo + let primaryKey: PrimaryKeyInfo - @usableFromInline init(_ db: Database, _ record: Record) throws { self.db = db databaseTableName = type(of: record).databaseTableName @@ -676,7 +666,6 @@ final class DAO { GRDBPrecondition(!persistenceContainer.isEmpty, "\(type(of: record)): invalid empty persistence container") } - @usableFromInline func insertStatement(onConflict: Database.ConflictResolution) throws -> Statement { let query = InsertQuery( onConflict: onConflict, @@ -688,7 +677,6 @@ final class DAO { } /// Returns nil if and only if primary key is nil - @usableFromInline func updateStatement(columns: Set, onConflict: Database.ConflictResolution) throws -> Statement? { // Fail early if primary key does not resolve to a database row. let primaryKeyColumns = primaryKey.columns @@ -738,7 +726,6 @@ final class DAO { } /// Returns nil if and only if primary key is nil - @usableFromInline func deleteStatement() throws -> Statement? { // Fail early if primary key does not resolve to a database row. let primaryKeyColumns = primaryKey.columns @@ -758,7 +745,6 @@ final class DAO { } /// Returns nil if and only if primary key is nil - @usableFromInline func existsStatement() throws -> Statement? { // Fail early if primary key does not resolve to a database row. let primaryKeyColumns = primaryKey.columns @@ -778,7 +764,6 @@ final class DAO { } /// Throws a PersistenceError.recordNotFound error - @usableFromInline func makeRecordNotFoundError() -> Error { let key = Dictionary(uniqueKeysWithValues: primaryKey.columns.map { ($0, persistenceContainer[caseInsensitive: $0]?.databaseValue ?? .null) diff --git a/GRDB/Utils/OrderedDictionary.swift b/GRDB/Utils/OrderedDictionary.swift index 4e2b6dfa5..3bd60eaf2 100644 --- a/GRDB/Utils/OrderedDictionary.swift +++ b/GRDB/Utils/OrderedDictionary.swift @@ -8,10 +8,9 @@ /// dict["bar"] // 2 /// dict["qux"] // nil /// dict.map { $0.key } // ["foo", "bar"], in this order. -@usableFromInline struct OrderedDictionary { - @usableFromInline /* private(set) */ var keys: [Key] - @usableFromInline /* private(set) */ var dictionary: [Key: Value] + private(set) var keys: [Key] + private(set) var dictionary: [Key: Value] var values: [Value] { keys.map { dictionary[$0]! } } @@ -35,7 +34,6 @@ struct OrderedDictionary { } /// Returns the value associated with key, or nil. - @usableFromInline subscript(_ key: Key) -> Value? { get { dictionary[key] } set { @@ -48,7 +46,6 @@ struct OrderedDictionary { } /// Returns the value associated with key, or the default value. - @inlinable subscript(_ key: Key, default defaultValue: Value) -> Value { get { dictionary[key] ?? defaultValue } set { self[key] = newValue } @@ -72,7 +69,6 @@ struct OrderedDictionary { /// original value. If the given key is not present in the dictionary, this /// method appends the key-value pair and returns nil. @discardableResult - @usableFromInline mutating func updateValue(_ value: Value, forKey key: Key) -> Value? { if let oldValue = dictionary.updateValue(value, forKey: key) { return oldValue @@ -83,7 +79,6 @@ struct OrderedDictionary { /// Removes the value associated with key. @discardableResult - @inlinable mutating func removeValue(forKey key: Key) -> Value? { guard let value = dictionary.removeValue(forKey: key) else { return nil @@ -173,16 +168,13 @@ struct OrderedDictionary { } extension OrderedDictionary: Collection { - @usableFromInline typealias Index = Int - @usableFromInline var startIndex: Int { 0 } - @usableFromInline var endIndex: Int { keys.count } + var startIndex: Int { 0 } + var endIndex: Int { keys.count } - @usableFromInline func index(after i: Int) -> Int { i + 1 } - @usableFromInline subscript(position: Int) -> (key: Key, value: Value) { let key = keys[position] return (key: key, value: dictionary[key]!) @@ -190,7 +182,6 @@ extension OrderedDictionary: Collection { } extension OrderedDictionary: ExpressibleByDictionaryLiteral { - @usableFromInline init(dictionaryLiteral elements: (Key, Value)...) { self.keys = elements.map { $0.0 } self.dictionary = Dictionary(uniqueKeysWithValues: elements) @@ -198,7 +189,6 @@ extension OrderedDictionary: ExpressibleByDictionaryLiteral { } extension OrderedDictionary: Equatable where Value: Equatable { - @usableFromInline static func == (lhs: OrderedDictionary, rhs: OrderedDictionary) -> Bool { (lhs.keys == rhs.keys) && (lhs.dictionary == rhs.dictionary) } diff --git a/GRDB/Utils/Refinable.swift b/GRDB/Utils/Refinable.swift index 253cbf8d4..15ce2f1c1 100644 --- a/GRDB/Utils/Refinable.swift +++ b/GRDB/Utils/Refinable.swift @@ -28,7 +28,6 @@ extension Refinable { /// } /// newPlayer.name // "Arthur" /// newPlayer.score // 100 - @inline(__always) func with(_ update: (inout Self) throws -> Void) rethrows -> Self { var result = self try update(&result) diff --git a/GRDB/Utils/Utils.swift b/GRDB/Utils/Utils.swift index 01c296fcb..615e28032 100644 --- a/GRDB/Utils/Utils.swift +++ b/GRDB/Utils/Utils.swift @@ -7,7 +7,7 @@ extension String { /// SQL query. /// /// db.execute(sql: "SELECT * FROM \(tableName.quotedDatabaseIdentifier)") - @inlinable public var quotedDatabaseIdentifier: String { + public var quotedDatabaseIdentifier: String { // See return "\"\(self)\"" } @@ -16,7 +16,6 @@ extension String { /// Return as many question marks separated with commas as the *count* argument. /// /// databaseQuestionMarks(count: 3) // "?,?,?" -@inlinable public func databaseQuestionMarks(count: Int) -> String { repeatElement("?", count: count).joined(separator: ",") } @@ -37,7 +36,6 @@ extension Optional: _OptionalProtocol { } // MARK: - Internal /// Reserved for GRDB: do not use. -@inlinable func GRDBPrecondition( _ condition: @autoclosure() -> Bool, _ message: @autoclosure() -> String = "", @@ -52,7 +50,6 @@ func GRDBPrecondition( } } -@inlinable func fatalError(_ error: E) -> Never { try! { throw error }() } @@ -93,7 +90,6 @@ extension DispatchQueue { } extension Sequence { - @inlinable func countElements(where predicate: (Element) throws -> Bool) rethrows -> Int { var count = 0 for e in self where try predicate(e) { @@ -112,7 +108,6 @@ extension Sequence { /// try throwingFirstError( /// execute: work, /// finally: cleanup) -@inline(__always) func throwingFirstError(execute: () throws -> T, finally: () throws -> Void) throws -> T { var result: T? var firstError: Error? @@ -171,8 +166,6 @@ func concat(_ rhs: ((T) -> Void)?, _ lhs: ((T) -> Void)?) -> ((T) -> Void)? { } extension NSRecursiveLock { - @inlinable - @inline(__always) func synchronized( _ message: @autoclosure () -> String = #function, _ block: () throws -> T) @@ -199,8 +192,6 @@ extension NSRecursiveLock { /// Performs the side effect outside of the synchronized block. This allows /// avoiding deadlocks, when the side effect feedbacks. - @inlinable - @inline(__always) func synchronized( _ message: @autoclosure () -> String = #function, _ block: (inout (() -> Void)?) -> Void) From 59c4d420766f4bec9a2068502b1a501dd2c6bc63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 21 Aug 2021 14:08:46 +0200 Subject: [PATCH 04/19] Remove test warnings with BUILD_LIBRARY_FOR_DISTRIBUTION --- GRDB/Core/Database.swift | 1 + GRDB/Core/DatabaseValue.swift | 1 + GRDB/Core/TransactionObserver.swift | 1 + GRDB/QueryInterface/SQL/Column.swift | 6 ++++++ 4 files changed, 9 insertions(+) diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index 953089776..6554aecd4 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -1596,6 +1596,7 @@ extension Database { } /// Confirms or cancels the changes performed by a transaction or savepoint. + @frozen public enum TransactionCompletion { /// Confirms changes case commit diff --git a/GRDB/Core/DatabaseValue.swift b/GRDB/Core/DatabaseValue.swift index 80d147c59..3fcff1a1b 100644 --- a/GRDB/Core/DatabaseValue.swift +++ b/GRDB/Core/DatabaseValue.swift @@ -13,6 +13,7 @@ public struct DatabaseValue: Hashable, CustomStringConvertible, DatabaseValueCon public static let null = DatabaseValue(storage: .null) /// An SQLite storage (NULL, INTEGER, REAL, TEXT, BLOB). + @frozen public enum Storage: Equatable { /// The NULL storage class. case null diff --git a/GRDB/Core/TransactionObserver.swift b/GRDB/Core/TransactionObserver.swift index 129c55153..0eafd0a3f 100644 --- a/GRDB/Core/TransactionObserver.swift +++ b/GRDB/Core/TransactionObserver.swift @@ -881,6 +881,7 @@ typealias StatementObservation = (TransactionObservation, DatabaseEventPredicate /// A kind of database event. See the `TransactionObserver` protocol for /// more information. +@frozen public enum DatabaseEventKind { /// The insertion of a row in a database table case insert(tableName: String) diff --git a/GRDB/QueryInterface/SQL/Column.swift b/GRDB/QueryInterface/SQL/Column.swift index 7f3f35147..2a658eb44 100644 --- a/GRDB/QueryInterface/SQL/Column.swift +++ b/GRDB/QueryInterface/SQL/Column.swift @@ -52,6 +52,12 @@ public struct Column: ColumnExpression, Equatable { public init(_ codingKey: CodingKey) { self.name = codingKey.stringValue } + + // Avoid a wrong resolution when BUILD_LIBRARY_FOR_DISTRIBUTION is set + @_disfavoredOverload + public static func == (lhs: Column, rhs: Column) -> Bool { + lhs.name == rhs.name + } } /// Support for column enums: From 18e9b1b9aa5b557ee19bcf3af61a596548712500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 21 Aug 2021 14:53:11 +0200 Subject: [PATCH 05/19] Specialize StatementColumnConvertible decoding --- GRDB/Core/DatabaseValueConvertible.swift | 2 + GRDB/Core/Row.swift | 45 +++++++++++++++++----- GRDB/Core/RowDecodingError.swift | 9 +++++ GRDB/Core/StatementColumnConvertible.swift | 4 ++ 4 files changed, 50 insertions(+), 10 deletions(-) diff --git a/GRDB/Core/DatabaseValueConvertible.swift b/GRDB/Core/DatabaseValueConvertible.swift index 8ff8bd82b..98c63165a 100644 --- a/GRDB/Core/DatabaseValueConvertible.swift +++ b/GRDB/Core/DatabaseValueConvertible.swift @@ -57,6 +57,7 @@ extension DatabaseValueConvertible { return try decode(fromDatabaseValue: dbValue, context: context()) } + @usableFromInline static func decode(fromRow row: Row, atUncheckedIndex index: Int) throws -> Self { if let sqliteStatement = row.sqliteStatement { return try decode( @@ -100,6 +101,7 @@ extension DatabaseValueConvertible { } } + @usableFromInline static func decodeIfPresent(fromRow row: Row, atUncheckedIndex index: Int) throws -> Self? { if let sqliteStatement = row.sqliteStatement { return try decodeIfPresent( diff --git a/GRDB/Core/Row.swift b/GRDB/Core/Row.swift index f51ab18ba..57aad090f 100644 --- a/GRDB/Core/Row.swift +++ b/GRDB/Core/Row.swift @@ -15,6 +15,7 @@ public final class Row: Equatable, Hashable, RandomAccessCollection, /// let rows = try Row.fetchCursor(db, sql: "SELECT ...") /// let players = try Player.fetchAll(db, sql: "SELECT ...") let statement: Statement? + @usableFromInline let sqliteStatement: SQLiteStatement? /// The number of columns in the row. @@ -154,6 +155,7 @@ extension Row { index(forColumn: columnName) != nil } + @usableFromInline func index(forColumn name: String) -> Int? { impl.index(forColumn: name) } @@ -164,7 +166,8 @@ extension Row { // MARK: - Extracting Values /// Fatal errors if index is out of bounds - private func checkedIndex(_ index: Int, file: StaticString = #file, line: UInt = #line) -> Int { + @usableFromInline + /* private */ func _checkedIndex(_ index: Int, file: StaticString = #file, line: UInt = #line) -> Int { GRDBPrecondition(index >= 0 && index < count, "row index out of range", file: file, line: line) return index } @@ -201,7 +204,7 @@ extension Row { /// in performance-critical code because it can avoid decoding database /// values. public func hasNull(atIndex index: Int) -> Bool { - impl.hasNull(atUncheckedIndex: checkedIndex(index)) + impl.hasNull(atUncheckedIndex: _checkedIndex(index)) } /// Returns Int64, Double, String, Data or nil, depending on the value @@ -210,7 +213,7 @@ extension Row { /// Indexes span from 0 for the leftmost column to (row.count - 1) for the /// righmost column. public subscript(_ index: Int) -> DatabaseValueConvertible? { - impl.databaseValue(atUncheckedIndex: checkedIndex(index)).storage.value + impl.databaseValue(atUncheckedIndex: _checkedIndex(index)).storage.value } /// Returns the value at given index, converted to the requested type. @@ -221,6 +224,7 @@ extension Row { /// If the SQLite value is NULL, the result is nil. Otherwise the SQLite /// value is converted to the requested type `Value`. Should this conversion /// fail, a fatal error is raised. + @inlinable public subscript(_ index: Int) -> Value? { try! decodeIfPresent(Value.self, atIndex: index) } @@ -237,6 +241,7 @@ extension Row { /// This method exists as an optimization opportunity for types that adopt /// StatementColumnConvertible. It *may* trigger SQLite built-in conversions /// (see ). + @inlinable public subscript(_ index: Int) -> Value? { try! decodeIfPresent(Value.self, atIndex: index) } @@ -248,6 +253,7 @@ extension Row { /// /// This method crashes if the fetched SQLite value is NULL, or if the /// SQLite value can not be converted to `Value`. + @inlinable public subscript(_ index: Int) -> Value { try! decode(Value.self, atIndex: index) } @@ -263,6 +269,7 @@ extension Row { /// This method exists as an optimization opportunity for types that adopt /// StatementColumnConvertible. It *may* trigger SQLite built-in conversions /// (see ). + @inlinable public subscript(_ index: Int) -> Value { try! decode(Value.self, atIndex: index) } @@ -296,6 +303,7 @@ extension Row { /// If the column is missing or if the SQLite value is NULL, the result is /// nil. Otherwise the SQLite value is converted to the requested type /// `Value`. Should this conversion fail, a fatal error is raised. + @inlinable public subscript(_ columnName: String) -> Value? { try! decodeIfPresent(Value.self, forKey: columnName) } @@ -312,6 +320,7 @@ extension Row { /// This method exists as an optimization opportunity for types that adopt /// StatementColumnConvertible. It *may* trigger SQLite built-in conversions /// (see ). + @inlinable public subscript(_ columnName: String) -> Value? { try! decodeIfPresent(Value.self, forKey: columnName) } @@ -325,6 +334,7 @@ extension Row { /// /// This method crashes if the fetched SQLite value is NULL, or if the /// SQLite value can not be converted to `Value`. + @inlinable public subscript(_ columnName: String) -> Value { try! decode(Value.self, forKey: columnName) } @@ -342,6 +352,7 @@ extension Row { /// This method exists as an optimization opportunity for types that adopt /// StatementColumnConvertible. It *may* trigger SQLite built-in conversions /// (see ). + @inlinable public subscript(_ columnName: String) -> Value { try! decode(Value.self, forKey: columnName) } @@ -365,6 +376,7 @@ extension Row { /// If the column is missing or if the SQLite value is NULL, the result is /// nil. Otherwise the SQLite value is converted to the requested type /// `Value`. Should this conversion fail, a fatal error is raised. + @inlinable public subscript(_ column: Column) -> Value? { try! decodeIfPresent(Value.self, forKey: column.name) } @@ -381,6 +393,7 @@ extension Row { /// This method exists as an optimization opportunity for types that adopt /// StatementColumnConvertible. It *may* trigger SQLite built-in conversions /// (see ). + @inlinable public subscript(_ column: Column) -> Value? where @@ -399,6 +412,7 @@ extension Row { /// /// This method crashes if the fetched SQLite value is NULL, or if the /// SQLite value can not be converted to `Value`. + @inlinable public subscript(_ column: Column) -> Value { try! decode(Value.self, forKey: column.name) } @@ -416,6 +430,7 @@ extension Row { /// This method exists as an optimization opportunity for types that adopt /// StatementColumnConvertible. It *may* trigger SQLite built-in conversions /// (see ). + @inlinable public subscript(_ column: Column) -> Value where @@ -691,12 +706,13 @@ extension Row { /// If the SQLite value is NULL, the result is nil. Otherwise the SQLite /// value is converted to the requested type `Value`. If the conversion /// fail, a `RowDecodingError` is thrown. + @inlinable func decodeIfPresent( _ type: Value.Type = Value.self, atIndex index: Int) throws -> Value? { - try Value.decodeIfPresent(fromRow: self, atUncheckedIndex: checkedIndex(index)) + try Value.decodeIfPresent(fromRow: self, atUncheckedIndex: _checkedIndex(index)) } /// Returns the value at given index, converted to the requested type. @@ -706,12 +722,13 @@ extension Row { /// /// If the SQLite value is NULL, or if the conversion fails, a /// `RowDecodingError` is thrown. + @inlinable func decode( _ type: Value.Type = Value.self, atIndex index: Int) throws -> Value { - try Value.decode(fromRow: self, atUncheckedIndex: checkedIndex(index)) + try Value.decode(fromRow: self, atUncheckedIndex: _checkedIndex(index)) } /// Returns the value at given column, converted to the requested type. @@ -722,6 +739,7 @@ extension Row { /// If the column is missing or if the SQLite value is NULL, the result is /// nil. Otherwise the SQLite value is converted to the requested type /// `Value`. If the conversion fails, a `RowDecodingError` is thrown. + @inlinable func decodeIfPresent( _ type: Value.Type = Value.self, forKey columnName: String) @@ -741,6 +759,7 @@ extension Row { /// If the row does not contain the column, or if the SQLite value is NULL, /// or if the SQLite value can not be converted to `Value`, a /// `RowDecodingError` is thrown. + @inlinable func decode( _ type: Value.Type = Value.self, forKey columnName: String) @@ -768,12 +787,13 @@ extension Row { /// This method exists as an optimization opportunity for types that adopt /// StatementColumnConvertible. It *may* trigger SQLite built-in conversions /// (see ). + @inlinable func decodeIfPresent( _ type: Value.Type = Value.self, atIndex index: Int) throws -> Value? { - try Value.fastDecodeIfPresent(fromRow: self, atUncheckedIndex: checkedIndex(index)) + try Value.fastDecodeIfPresent(fromRow: self, atUncheckedIndex: _checkedIndex(index)) } /// Returns the value at given index, converted to the requested type. @@ -787,12 +807,13 @@ extension Row { /// This method exists as an optimization opportunity for types that adopt /// StatementColumnConvertible. It *may* trigger SQLite built-in conversions /// (see ). + @inlinable func decode( _ type: Value.Type = Value.self, atIndex index: Int) throws -> Value { - try Value.fastDecode(fromRow: self, atUncheckedIndex: checkedIndex(index)) + try Value.fastDecode(fromRow: self, atUncheckedIndex: _checkedIndex(index)) } /// Returns the value at given column, converted to the requested type. @@ -807,6 +828,7 @@ extension Row { /// This method exists as an optimization opportunity for types that adopt /// StatementColumnConvertible. It *may* trigger SQLite built-in conversions /// (see ). + @inlinable func decodeIfPresent( _ type: Value.Type = Value.self, forKey columnName: String) @@ -830,6 +852,7 @@ extension Row { /// This method exists as an optimization opportunity for types that adopt /// StatementColumnConvertible. It *may* trigger SQLite built-in conversions /// (see ). + @inlinable func decode( _ type: Value.Type = Value.self, forKey columnName: String) @@ -842,6 +865,7 @@ extension Row { } // Support for fast decoding in scoped rows + @usableFromInline func fastDecode( _ type: Value.Type, atUncheckedIndex index: Int) @@ -851,6 +875,7 @@ extension Row { } // Support for fast decoding in scoped rows + @usableFromInline func fastDecodeIfPresent( _ type: Value.Type, atUncheckedIndex index: Int) @@ -874,7 +899,7 @@ extension Row { /// The returned data does not owns its bytes: it must not be used longer /// than the row's lifetime. func decodeDataNoCopyIfPresent(atIndex index: Int) throws -> Data? { - try impl.fastDecodeDataNoCopyIfPresent(atUncheckedIndex: checkedIndex(index)) + try impl.fastDecodeDataNoCopyIfPresent(atUncheckedIndex: _checkedIndex(index)) } /// Returns the Data at given index. @@ -888,7 +913,7 @@ extension Row { /// The returned data does not owns its bytes: it must not be used longer /// than the row's lifetime. func decodeDataNoCopy(atIndex index: Int) throws -> Data { - try impl.fastDecodeDataNoCopy(atUncheckedIndex: checkedIndex(index)) + try impl.fastDecodeDataNoCopy(atUncheckedIndex: _checkedIndex(index)) } /// Returns the optional Data at given column. @@ -1632,7 +1657,7 @@ extension Row { /// Accesses the (ColumnName, DatabaseValue) pair at given index. public subscript(position: RowIndex) -> (String, DatabaseValue) { - let index = checkedIndex(position.index) + let index = _checkedIndex(position.index) return ( impl.columnName(atUncheckedIndex: index), impl.databaseValue(atUncheckedIndex: index)) diff --git a/GRDB/Core/RowDecodingError.swift b/GRDB/Core/RowDecodingError.swift index fc3bf1e08..e37ba06e5 100644 --- a/GRDB/Core/RowDecodingError.swift +++ b/GRDB/Core/RowDecodingError.swift @@ -1,4 +1,5 @@ /// A key that is used to decode a value in a row +@usableFromInline enum RowKey: Hashable { /// A column name case columnName(String) @@ -14,9 +15,12 @@ enum RowKey: Hashable { } /// A decoding error +@usableFromInline enum RowDecodingError: Error { + @usableFromInline struct Context: CustomDebugStringConvertible { /// A description of what went wrong, for debugging purposes. + @usableFromInline let debugDescription: String /// The row that could not be decoded @@ -68,6 +72,7 @@ enum RowDecodingError: Error { /// Convenience method that builds the /// `could not decode from database value ` error message. + @usableFromInline static func valueMismatch( _ type: Any.Type, sqliteStatement: SQLiteStatement, @@ -97,6 +102,7 @@ enum RowDecodingError: Error { /// Convenience method that builds the `column not found: ` /// error message. + @usableFromInline static func columnNotFound(_ columnName: String, context: RowDecodingContext) -> Self { keyNotFound( .columnName(columnName), @@ -106,6 +112,7 @@ enum RowDecodingError: Error { } } +@usableFromInline struct RowDecodingContext { /// The row that is decoded let row: Row @@ -118,6 +125,7 @@ struct RowDecodingContext { /// The SQL query arguments let statementArguments: StatementArguments? + @usableFromInline init(row: Row, key: RowKey? = nil) { if let statement = row.statement { self.key = key @@ -147,6 +155,7 @@ struct RowDecodingContext { } extension RowDecodingError: CustomStringConvertible { + @usableFromInline var description: String { let context = self.context let row = context.row diff --git a/GRDB/Core/StatementColumnConvertible.swift b/GRDB/Core/StatementColumnConvertible.swift index 67481a78e..e4024dd63 100644 --- a/GRDB/Core/StatementColumnConvertible.swift +++ b/GRDB/Core/StatementColumnConvertible.swift @@ -45,6 +45,7 @@ public protocol StatementColumnConvertible { // MARK: - Conversions extension DatabaseValueConvertible where Self: StatementColumnConvertible { + @inlinable static func fastDecode( fromStatement sqliteStatement: SQLiteStatement, atUncheckedIndex index: Int32, @@ -63,6 +64,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { return value } + @inlinable static func fastDecode( fromRow row: Row, atUncheckedIndex index: Int) @@ -78,6 +80,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { return try row.fastDecode(Self.self, atUncheckedIndex: index) } + @inlinable static func fastDecodeIfPresent( fromStatement sqliteStatement: SQLiteStatement, atUncheckedIndex index: Int32, @@ -97,6 +100,7 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { return value } + @inlinable static func fastDecodeIfPresent( fromRow row: Row, atUncheckedIndex index: Int) From e2c9734df12076fbe579f76265f01eb090b6ae86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 21 Aug 2021 15:22:02 +0200 Subject: [PATCH 06/19] Specialize StatementColumnConvertible cursors --- GRDB/Core/Database+Statements.swift | 3 +++ GRDB/Core/DatabaseError.swift | 1 + GRDB/Core/RowDecodingError.swift | 1 + GRDB/Core/Statement.swift | 1 + GRDB/Core/StatementAuthorizer.swift | 1 + GRDB/Core/StatementColumnConvertible.swift | 24 +++++++++++++--------- 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/GRDB/Core/Database+Statements.swift b/GRDB/Core/Database+Statements.swift index c38870d69..d1d517617 100644 --- a/GRDB/Core/Database+Statements.swift +++ b/GRDB/Core/Database+Statements.swift @@ -588,6 +588,7 @@ extension Database { /// Returns the authorizer that should be used during statement execution /// (this allows preventing the truncate optimization when there exists a /// transaction observer for row deletion). + @usableFromInline func statementWillExecute(_ statement: Statement) throws -> StatementAuthorizer? { // Two things must prevent the statement from executing: aborted // transactions, and database suspension. @@ -603,6 +604,7 @@ extension Database { /// May throw a cancelled commit error, if a transaction observer cancels /// an empty transaction. + @usableFromInline func statementDidExecute(_ statement: Statement) throws { if statement.invalidatesDatabaseSchemaCache { clearSchemaCache() @@ -612,6 +614,7 @@ extension Database { } /// Always throws an error + @usableFromInline func statementDidFail(_ statement: Statement, withResultCode resultCode: Int32) throws -> Never { // Failed statements can not be reused, because sqlite3_reset won't // be able to restore the statement to its initial state: diff --git a/GRDB/Core/DatabaseError.swift b/GRDB/Core/DatabaseError.swift index d492e55dd..9fda1eb42 100644 --- a/GRDB/Core/DatabaseError.swift +++ b/GRDB/Core/DatabaseError.swift @@ -248,6 +248,7 @@ public struct DatabaseError: Error, CustomStringConvertible, CustomNSError { /// /// This initializer is not public because library user is not supposed to /// be exposed to raw result codes. + @usableFromInline init(resultCode: CInt, message: String? = nil, sql: String? = nil, arguments: StatementArguments? = nil) { self.init(resultCode: ResultCode(rawValue: resultCode), message: message, sql: sql, arguments: arguments) } diff --git a/GRDB/Core/RowDecodingError.swift b/GRDB/Core/RowDecodingError.swift index e37ba06e5..cff8dbf4b 100644 --- a/GRDB/Core/RowDecodingError.swift +++ b/GRDB/Core/RowDecodingError.swift @@ -146,6 +146,7 @@ struct RowDecodingContext { } /// Convenience initializer + @usableFromInline init(statement: Statement, index: Int) { self.key = .columnIndex(index) self.row = Row(copiedFromSQLiteStatement: statement.sqliteStatement, statement: statement) diff --git a/GRDB/Core/Statement.swift b/GRDB/Core/Statement.swift index 5946ce420..802293c1c 100644 --- a/GRDB/Core/Statement.swift +++ b/GRDB/Core/Statement.swift @@ -58,6 +58,7 @@ public final class Statement { sqlite3_stmt_readonly(sqliteStatement) != 0 } + @usableFromInline unowned let database: Database /// Cache for index(ofColumn:). Keys are lowercase. diff --git a/GRDB/Core/StatementAuthorizer.swift b/GRDB/Core/StatementAuthorizer.swift index a19b83ce9..44fea582c 100644 --- a/GRDB/Core/StatementAuthorizer.swift +++ b/GRDB/Core/StatementAuthorizer.swift @@ -3,6 +3,7 @@ import Glibc #endif /// A protocol around sqlite3_set_authorizer +@usableFromInline protocol StatementAuthorizer: AnyObject { func authorize( _ actionCode: Int32, diff --git a/GRDB/Core/StatementColumnConvertible.swift b/GRDB/Core/StatementColumnConvertible.swift index e4024dd63..cd95a98af 100644 --- a/GRDB/Core/StatementColumnConvertible.swift +++ b/GRDB/Core/StatementColumnConvertible.swift @@ -129,14 +129,15 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { /// } /// } public final class FastDatabaseValueCursor : Cursor { - private enum _State { + @usableFromInline + enum _State { case idle, busy, done, failed } - private let _statement: Statement - private let _columnIndex: Int32 - private let _sqliteStatement: SQLiteStatement - private var _state = _State.idle + @usableFromInline let _statement: Statement + @usableFromInline let _columnIndex: Int32 + @usableFromInline let _sqliteStatement: SQLiteStatement + @usableFromInline var _state = _State.idle init(statement: Statement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws { _statement = statement @@ -162,6 +163,7 @@ public final class FastDatabaseValueCursor Value? { switch _state { case .done: @@ -212,14 +214,15 @@ public final class FastDatabaseValueCursor: Cursor where Value: DatabaseValueConvertible & StatementColumnConvertible { - private enum _State { + @usableFromInline + enum _State { case idle, busy, done, failed } - private let _statement: Statement - private let _columnIndex: Int32 - private let _sqliteStatement: SQLiteStatement - private var _state = _State.idle + @usableFromInline let _statement: Statement + @usableFromInline let _columnIndex: Int32 + @usableFromInline let _sqliteStatement: SQLiteStatement + @usableFromInline var _state = _State.idle init(statement: Statement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws { _statement = statement @@ -245,6 +248,7 @@ where Value: DatabaseValueConvertible & StatementColumnConvertible try? _statement.reset() } + @inlinable public func next() throws -> Value?? { switch _state { case .done: From e6cdbb156d0408315b1db3a4742393cb2c128bce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 21 Aug 2021 15:38:20 +0200 Subject: [PATCH 07/19] FAQ: Does GRDB support library evolution and ABI stability --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 5e301a1d4..5f55af51d 100644 --- a/README.md +++ b/README.md @@ -7900,6 +7900,7 @@ FAQ - [How do I monitor the duration of database statements execution?](#how-do-i-monitor-the-duration-of-database-statements-execution) - [What Are Experimental Features?](#what-are-experimental-features) +- [Does GRDB support library evolution and ABI stability?](does-grdb-support-library-evolution-and-abi-stability) **[FAQ: Associations](#faq-associations)** @@ -8028,6 +8029,7 @@ db.trace { event in - :arrow_up: [FAQ] - [How do I monitor the duration of database statements execution?](#how-do-i-monitor-the-duration-of-database-statements-execution) - [What Are Experimental Features?](#what-are-experimental-features) +- [Does GRDB support library evolution and ABI stability?](does-grdb-support-library-evolution-and-abi-stability) ### How do I monitor the duration of database statements execution? @@ -8054,6 +8056,11 @@ try dbQueue.read { db in } ``` +### Does GRDB support library evolution and ABI stability? + +No, GRDB does not support library evolution and ABI stability. The only promise is API stability according to [semantic versioning](http://semver.org), with an exception for [experimental features](#what-are-experimental-features). + +Yet, GRDB can be built with the "Build Libraries for Distribution" Xcode option (`BUILD_LIBRARY_FOR_DISTRIBUTION`), so that you can build binary frameworks at your convenience. ## FAQ: Associations From 6639e9c598d7a783a0df9db7d2e5beac1067f1fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 21 Aug 2021 15:55:37 +0200 Subject: [PATCH 08/19] CHANGELOG --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12a9f51d0..c8788f36e 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 +- [Development Branch](#development-branch) - `5.9.x` Releases - [5.9.0](#590) - `5.8.x` Releases - [5.8.0](#580) - `5.7.x` Releases - [5.7.0](#570) | [5.7.1](#571) | [5.7.2](#572) | [5.7.3](#573) | [5.7.4](#574) @@ -76,6 +77,12 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: --- +## Development Branch + +- **New**: [#1036](https://github.com/groue/GRDB.swift/pull/1036) by [@groue](https://github.com/groue): Restore minimal CI tests +- **New**: [#1037](https://github.com/groue/GRDB.swift/pull/1037) by [@groue](https://github.com/groue): Support BUILD_LIBRARY_FOR_DISTRIBUTION + + ## 5.9.0 Released August 15, 2021 • [diff](https://github.com/groue/GRDB.swift/compare/v5.8.0...v5.9.0) From 8f7a2b6a8ef5f8402949bfde00f1194010ed77ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 21 Aug 2021 18:18:57 +0200 Subject: [PATCH 09/19] Documentation: Combine and Data Consistency --- CHANGELOG.md | 1 + Documentation/Combine.md | 106 +++++++++++++++++++++++++++------------ 2 files changed, 76 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8788f36e..d6ef2e8d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,6 +81,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: - **New**: [#1036](https://github.com/groue/GRDB.swift/pull/1036) by [@groue](https://github.com/groue): Restore minimal CI tests - **New**: [#1037](https://github.com/groue/GRDB.swift/pull/1037) by [@groue](https://github.com/groue): Support BUILD_LIBRARY_FOR_DISTRIBUTION +- **Documentation Update**: A new [Combine and Data Consistency](Documentation/Combine.md#combine-and-data-consistency) chapter explains how to make sure database publishers do not break important database invariants. ## 5.9.0 diff --git a/Documentation/Combine.md b/Documentation/Combine.md index 3e47b8338..b83f71835 100644 --- a/Documentation/Combine.md +++ b/Documentation/Combine.md @@ -7,6 +7,7 @@ GRDB ❤️ Combine - [Demo Application] - [Asynchronous Database Access] - [Database Observation] +- [Combine and Data Consistency]: take care when you combine database publishers together ## Usage @@ -248,37 +249,6 @@ This publisher has the same behavior as ValueObservation: See [ValueObservation Scheduling](../README.md#valueobservation-scheduling) for more information. -:warning: **ValueObservation and Data Consistency** - -When you compose ValueObservation publishers together with the [combineLatest](https://developer.apple.com/documentation/combine/publisher/3333677-combinelatest) operator, you lose all guarantees of [data consistency](https://en.wikipedia.org/wiki/Consistency_(database_systems)). - -Instead, compose requests together into **one single** ValueObservation, as below: - -```swift -struct HallOfFame { - var totalPlayerCount: Int - var bestPlayers: [Player] -} - -// DATA CONSISTENCY GUARANTEED -let hallOfFamePublisher = ValueObservation - .tracking { db -> HallOfFame in - let totalPlayerCount = try Player.fetchCount(db) - - let bestPlayers = try Player - .order(Column("score").desc) - .limit(10) - .fetchAll(db) - - return HallOfFame( - totalPlayerCount: totalPlayerCount, - bestPlayers: bestPlayers) - } - .publisher(in: dbQueue) -``` - -See [ValueObservation] for more information. - #### `DatabaseRegionObservation.publisher(in:)` @@ -320,12 +290,86 @@ try dbQueue.write { db in See [DatabaseRegionObservation] for more information. +## Combine and Data Consistency + +When you compose database publishers together with Combine operators such as `combineLatest` or `zip`, you lose all guarantees of [data consistency](https://en.wikipedia.org/wiki/Consistency_(database_systems)). + +This is because each database publisher is isolated from others: each one of them sees its own state of the database. Whenever some database change is interleaved between publisher operations, publishers will process or publish values that may not fit well together. + +In other words, whenever you need to perform some database access or observation that depends on some database invariant, make sure you define one and only one database publisher instead of combining several publishers. This is how you will prevent eventual concurrent database writes from messing with your app, and introduce bugs. + +To this end, remember that *all database publishers can perform several requests*. + +In the example below, we are totally sure that the published `HallOfFame` values will never contain inconsistent values, because it is produced by one and ony one publisher: + +```swift +struct HallOfFame { + // Invariant: bestPlayers.count <= totalPlayerCount + var totalPlayerCount: Int + var bestPlayers: [Player] +} + +// CORRECT: DATA CONSISTENCY GUARANTEED +let hallOfFamePublisher = ValueObservation + .tracking { db -> HallOfFame in + // 1st request + let totalPlayerCount = try Player.fetchCount(db) + + // 2nd request + let bestPlayers = try Player + .order(Column("score").desc) + .limit(10) + .fetchAll(db) + + // 100% guaranteed + assert(bestPlayers.count <= totalPlayerCount) + + // Merge results together + return HallOfFame( + totalPlayerCount: totalPlayerCount, + bestPlayers: bestPlayers) + } + .publisher(in: dbQueue) +``` + +Compare with the incorrect version that combines two database publishers together: + +```swift +// OK +let totalPlayerCountPublisher = ValueObservation + .tracking(Player.fetchCount) + .publisher(in: dbQueue) + +// OK +let bestPlayerPublisher = ValueObservation + .tracking(Player + .order(Column("score").desc) + .limit(10) + .fetchAll) + .publisher(in: dbQueue) + +// NOT OK: DATA CONSISTENCY NOT GUARANTEED +let hallOfFamePublisher = totalPlayerCountPublisher + .combineLatest(bestPlayerPublisher) + .map(HallOfFame.init(totalPlayerCount:bestPlayers)) + +let cancellable = hallOfFamePublisher.sink( + receiveCompletion: { completion in ... }, + receiveValue: { hallOfFame in + // ASSERTION MAY FAIL if some players are deleted + // at the wrong time + assert(hallOfFame.bestPlayers.count <= hallOfFame.totalPlayerCount) + }) +``` + + [Database Connections]: ../README.md#database-connections [Usage]: #usage [Asynchronous Database Access]: #asynchronous-database-access [Combine]: https://developer.apple.com/documentation/combine [Database Changes Observation]: ../README.md#database-changes-observation [Database Observation]: #database-observation +[Combine and Data Consistency]: #combine-and-data-consistency [DatabaseRegionObservation]: ../README.md#databaseregionobservation [Demo Application]: DemoApps/GRDBCombineDemo/README.md [SQLite]: http://sqlite.org From 2f3311cd1e5911429b24c43f9b304362ddb76e00 Mon Sep 17 00:00:00 2001 From: Ethan Wong Date: Sun, 22 Aug 2021 16:12:39 +0800 Subject: [PATCH 10/19] Add match operator in ColumnExpression for FTS5 --- GRDB/QueryInterface/FTS5+QueryInterface.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/GRDB/QueryInterface/FTS5+QueryInterface.swift b/GRDB/QueryInterface/FTS5+QueryInterface.swift index 7ab62750a..e6c2c72b2 100644 --- a/GRDB/QueryInterface/FTS5+QueryInterface.swift +++ b/GRDB/QueryInterface/FTS5+QueryInterface.swift @@ -41,4 +41,18 @@ extension TableRecord { all().matching(pattern) } } + +extension ColumnExpression { + + /// A matching SQL expression with the `MATCH` SQL operator. + /// + /// // content MATCH '...' + /// Column("content").match(pattern) + /// + /// If the search pattern is nil, SQLite will evaluate the expression + /// to false. + public func match(_ pattern: FTS5Pattern?) -> SQLExpression { + .binary(.match, sqlExpression, pattern?.sqlExpression ?? .null) + } +} #endif From 836432c4ce69fb03c7bb77f1dc10bf17abf1590f Mon Sep 17 00:00:00 2001 From: Ethan Wong Date: Sun, 22 Aug 2021 16:30:07 +0800 Subject: [PATCH 11/19] Add tests of column matching expression for fts5 --- Tests/GRDBTests/FTS5RecordTests.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Tests/GRDBTests/FTS5RecordTests.swift b/Tests/GRDBTests/FTS5RecordTests.swift index 19c54c843..f854c9fdf 100644 --- a/Tests/GRDBTests/FTS5RecordTests.swift +++ b/Tests/GRDBTests/FTS5RecordTests.swift @@ -72,6 +72,9 @@ class FTS5RecordTests: GRDBTestCase { let pattern = FTS5Pattern(matchingAllTokensIn: "Herman Melville")! XCTAssertEqual(try Book.matching(pattern).fetchCount(db), 1) + XCTAssertEqual(try Book.filter(Column("books").match(pattern)).fetchCount(db), 1) + XCTAssertEqual(try Book.filter(Column("author").match(pattern)).fetchCount(db), 1) + XCTAssertEqual(try Book.filter(Column("title").match(pattern)).fetchCount(db), 0) } } @@ -86,6 +89,9 @@ class FTS5RecordTests: GRDBTestCase { let pattern = FTS5Pattern(matchingAllTokensIn: "") XCTAssertTrue(pattern == nil) XCTAssertEqual(try Book.matching(pattern).fetchCount(db), 0) + XCTAssertEqual(try Book.filter(Column("books").match(pattern)).fetchCount(db), 0) + XCTAssertEqual(try Book.filter(Column("author").match(pattern)).fetchCount(db), 0) + XCTAssertEqual(try Book.filter(Column("title").match(pattern)).fetchCount(db), 0) } } From 48ef6918979311f0d9362b16c4331636c8cc44b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 22 Aug 2021 11:03:18 +0200 Subject: [PATCH 12/19] Disallow FTS5 column matching against NULL SQLite just throws a syntax error --- GRDB/QueryInterface/FTS5+QueryInterface.swift | 7 ++----- Tests/GRDBTests/FTS5RecordTests.swift | 3 --- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/GRDB/QueryInterface/FTS5+QueryInterface.swift b/GRDB/QueryInterface/FTS5+QueryInterface.swift index e6c2c72b2..dcf0272ee 100644 --- a/GRDB/QueryInterface/FTS5+QueryInterface.swift +++ b/GRDB/QueryInterface/FTS5+QueryInterface.swift @@ -48,11 +48,8 @@ extension ColumnExpression { /// /// // content MATCH '...' /// Column("content").match(pattern) - /// - /// If the search pattern is nil, SQLite will evaluate the expression - /// to false. - public func match(_ pattern: FTS5Pattern?) -> SQLExpression { - .binary(.match, sqlExpression, pattern?.sqlExpression ?? .null) + public func match(_ pattern: FTS5Pattern) -> SQLExpression { + .binary(.match, sqlExpression, pattern.sqlExpression) } } #endif diff --git a/Tests/GRDBTests/FTS5RecordTests.swift b/Tests/GRDBTests/FTS5RecordTests.swift index f854c9fdf..fd1fcd26c 100644 --- a/Tests/GRDBTests/FTS5RecordTests.swift +++ b/Tests/GRDBTests/FTS5RecordTests.swift @@ -89,9 +89,6 @@ class FTS5RecordTests: GRDBTestCase { let pattern = FTS5Pattern(matchingAllTokensIn: "") XCTAssertTrue(pattern == nil) XCTAssertEqual(try Book.matching(pattern).fetchCount(db), 0) - XCTAssertEqual(try Book.filter(Column("books").match(pattern)).fetchCount(db), 0) - XCTAssertEqual(try Book.filter(Column("author").match(pattern)).fetchCount(db), 0) - XCTAssertEqual(try Book.filter(Column("title").match(pattern)).fetchCount(db), 0) } } From 8eff518850baec67126a918b6d65dc6877b03ef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 22 Aug 2021 11:03:54 +0200 Subject: [PATCH 13/19] Documentation for FTS5 column matching --- Documentation/FullTextSearch.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/FullTextSearch.md b/Documentation/FullTextSearch.md index 963f31811..13c496dee 100644 --- a/Documentation/FullTextSearch.md +++ b/Documentation/FullTextSearch.md @@ -540,7 +540,11 @@ let documents = try Document.fetchAll(db, Use them in the [query interface](../README.md#the-query-interface): ```swift +// Search in all columns let documents = try Document.matching(pattern).fetchAll(db) + +// Search in a specific column: +let documents = try Document.filter(Column("content").match(pattern)).fetchAll(db) ``` From 14b5eea277ccff013d27a978696f856a1c269da5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 22 Aug 2021 11:12:10 +0200 Subject: [PATCH 14/19] CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6ef2e8d1..e1cbbea66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,6 +81,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: - **New**: [#1036](https://github.com/groue/GRDB.swift/pull/1036) by [@groue](https://github.com/groue): Restore minimal CI tests - **New**: [#1037](https://github.com/groue/GRDB.swift/pull/1037) by [@groue](https://github.com/groue): Support BUILD_LIBRARY_FOR_DISTRIBUTION +- **New**: [#1038](https://github.com/groue/GRDB.swift/pull/1038) by [@GetToSet](https://github.com/GetToSet): Add match operator in ColumnExpression for FTS5 - **Documentation Update**: A new [Combine and Data Consistency](Documentation/Combine.md#combine-and-data-consistency) chapter explains how to make sure database publishers do not break important database invariants. From 0511fec001dd849d2fd3fc992dade37383766c7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 22 Aug 2021 12:42:53 +0200 Subject: [PATCH 15/19] SE-0299: enhance access to `Column.rowID` --- CHANGELOG.md | 1 + GRDB/QueryInterface/Request/RequestProtocols.swift | 4 ++++ GRDB/QueryInterface/SQL/Column.swift | 7 +++++++ GRDB/QueryInterface/SQL/SQLExpression.swift | 7 +++++++ README.md | 4 ++-- Support/GRDBDeploymentTarget.xcconfig | 3 +-- Tests/GRDBTests/DerivableRequestTests.swift | 8 ++++++++ Tests/GRDBTests/FTS3RecordTests.swift | 8 ++++++++ Tests/GRDBTests/FTS4RecordTests.swift | 8 ++++++++ Tests/GRDBTests/FTS5RecordTests.swift | 10 +++++++++- Tests/GRDBTests/RecordPrimaryKeyHiddenRowIDTests.swift | 8 ++++++++ 11 files changed, 63 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1cbbea66..9850633f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,6 +82,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: - **New**: [#1036](https://github.com/groue/GRDB.swift/pull/1036) by [@groue](https://github.com/groue): Restore minimal CI tests - **New**: [#1037](https://github.com/groue/GRDB.swift/pull/1037) by [@groue](https://github.com/groue): Support BUILD_LIBRARY_FOR_DISTRIBUTION - **New**: [#1038](https://github.com/groue/GRDB.swift/pull/1038) by [@GetToSet](https://github.com/GetToSet): Add match operator in ColumnExpression for FTS5 +- **New**: With Swift 5.5+, enhance access to `Column.rowID`. Row and PersistenceContainer subscripts now accept `row[.rowID]` and `container[.rowID]` ([SE-0299](https://github.com/apple/swift-evolution/blob/main/proposals/0299-extend-generic-static-member-lookup.md)) - **Documentation Update**: A new [Combine and Data Consistency](Documentation/Combine.md#combine-and-data-consistency) chapter explains how to make sure database publishers do not break important database invariants. diff --git a/GRDB/QueryInterface/Request/RequestProtocols.swift b/GRDB/QueryInterface/Request/RequestProtocols.swift index bbfe97130..39bafad3e 100644 --- a/GRDB/QueryInterface/Request/RequestProtocols.swift +++ b/GRDB/QueryInterface/Request/RequestProtocols.swift @@ -405,7 +405,11 @@ extension TableRequest where Self: AggregatingRequest { return [Column(rowIDColumn)] } else if primaryKey.tableHasRowID { // Prefer the rowid + #if compiler(>=5.5) + return [.rowID] + #else return [Column.rowID] + #endif } else { // WITHOUT ROWID table: group by primary key columns return primaryKey.columns.map { Column($0) } diff --git a/GRDB/QueryInterface/SQL/Column.swift b/GRDB/QueryInterface/SQL/Column.swift index 2a658eb44..d6d1299fb 100644 --- a/GRDB/QueryInterface/SQL/Column.swift +++ b/GRDB/QueryInterface/SQL/Column.swift @@ -30,6 +30,13 @@ extension ColumnExpression { } } +#if compiler(>=5.5) +extension ColumnExpression where Self == Column { + /// The hidden rowID column + public static var rowID: Self { Column.rowID } +} +#endif + /// A column in a database table. /// /// When you need to introduce your own column type, don't wrap a Column. diff --git a/GRDB/QueryInterface/SQL/SQLExpression.swift b/GRDB/QueryInterface/SQL/SQLExpression.swift index e76711e5f..99d0632b2 100644 --- a/GRDB/QueryInterface/SQL/SQLExpression.swift +++ b/GRDB/QueryInterface/SQL/SQLExpression.swift @@ -1565,6 +1565,13 @@ public protocol SQLExpressible { var sqlExpression: SQLExpression { get } } +#if compiler(>=5.5) +extension SQLExpressible where Self == Column { + /// The hidden rowID column + public static var rowID: Self { Column.rowID } +} +#endif + /// `SQLSpecificExpressible` is a protocol for all database-specific types that /// can be turned into an SQL expression. Types whose existence is not purely /// dedicated to the database should adopt the `SQLExpressible` diff --git a/README.md b/README.md index 5f55af51d..c3627c5d1 100644 --- a/README.md +++ b/README.md @@ -3581,7 +3581,7 @@ When SQLite won't let you provide an explicit primary key (as in [full-text](Doc var id: Int64? init(row: Row) { - id = row[Column.rowID] + id = row[Column.rowID] // or `row[.rowID]` with Swift 5.5+ } } ``` @@ -3600,7 +3600,7 @@ When SQLite won't let you provide an explicit primary key (as in [full-text](Doc var id: Int64? func encode(to container: inout PersistenceContainer) { - container[Column.rowID] = id + container[Column.rowID] = id // or `container[.rowID]` with Swift 5.5+ container["message"] = message container["date"] = date } diff --git a/Support/GRDBDeploymentTarget.xcconfig b/Support/GRDBDeploymentTarget.xcconfig index a88f9e56d..2247751b2 100644 --- a/Support/GRDBDeploymentTarget.xcconfig +++ b/Support/GRDBDeploymentTarget.xcconfig @@ -4,5 +4,4 @@ TVOS_DEPLOYMENT_TARGET = 9.0 WATCHOS_DEPLOYMENT_TARGET = 2.0 //// Compile with all opt-in APIs -//GCC_PREPROCESSOR_DEFINITIONS = $(inherited) GRDB_SQLITE_ENABLE_PREUPDATE_HOOK=1 -//OTHER_SWIFT_FLAGS = $(inherited) -D SQLITE_ENABLE_FTS5 -D SQLITE_ENABLE_PREUPDATE_HOOK +OTHER_SWIFT_FLAGS = $(inherited) -D SQLITE_ENABLE_FTS5 diff --git a/Tests/GRDBTests/DerivableRequestTests.swift b/Tests/GRDBTests/DerivableRequestTests.swift index b23ef6f3a..7d9c96cc2 100644 --- a/Tests/GRDBTests/DerivableRequestTests.swift +++ b/Tests/GRDBTests/DerivableRequestTests.swift @@ -25,10 +25,18 @@ private struct Book: FetchableRecord, PersistableRecord, Codable { static let databaseTableName = "book" static let author = belongsTo(Author.self) + #if compiler(>=5.5) + static let bookFts4 = hasOne(BookFts4.self, using: ForeignKey([.rowID])) + #else static let bookFts4 = hasOne(BookFts4.self, using: ForeignKey([Column.rowID])) + #endif #if SQLITE_ENABLE_FTS5 + #if compiler(>=5.5) + static let bookFts5 = hasOne(BookFts5.self, using: ForeignKey([.rowID])) + #else static let bookFts5 = hasOne(BookFts5.self, using: ForeignKey([Column.rowID])) #endif + #endif var author: QueryInterfaceRequest { request(for: Book.author) } } diff --git a/Tests/GRDBTests/FTS3RecordTests.swift b/Tests/GRDBTests/FTS3RecordTests.swift index 21aade5a6..d7f3ff400 100644 --- a/Tests/GRDBTests/FTS3RecordTests.swift +++ b/Tests/GRDBTests/FTS3RecordTests.swift @@ -10,7 +10,11 @@ private struct Book { extension Book : FetchableRecord { init(row: Row) { + #if compiler(>=5.5) + id = row[.rowID] + #else id = row[Column.rowID] + #endif title = row["title"] author = row["author"] body = row["body"] @@ -22,7 +26,11 @@ extension Book : MutablePersistableRecord { static let databaseSelection: [SQLSelectable] = [AllColumns(), Column.rowID] func encode(to container: inout PersistenceContainer) { + #if compiler(>=5.5) + container[.rowID] = id + #else container[Column.rowID] = id + #endif container["title"] = title container["author"] = author container["body"] = body diff --git a/Tests/GRDBTests/FTS4RecordTests.swift b/Tests/GRDBTests/FTS4RecordTests.swift index d6b00cda1..8f322063b 100644 --- a/Tests/GRDBTests/FTS4RecordTests.swift +++ b/Tests/GRDBTests/FTS4RecordTests.swift @@ -10,7 +10,11 @@ private struct Book { extension Book : FetchableRecord { init(row: Row) { + #if compiler(>=5.5) + id = row[.rowID] + #else id = row[Column.rowID] + #endif title = row["title"] author = row["author"] body = row["body"] @@ -22,7 +26,11 @@ extension Book : MutablePersistableRecord { static let databaseSelection: [SQLSelectable] = [AllColumns(), Column.rowID] func encode(to container: inout PersistenceContainer) { + #if compiler(>=5.5) + container[.rowID] = id + #else container[Column.rowID] = id + #endif container["title"] = title container["author"] = author container["body"] = body diff --git a/Tests/GRDBTests/FTS5RecordTests.swift b/Tests/GRDBTests/FTS5RecordTests.swift index fd1fcd26c..2e23f03f4 100644 --- a/Tests/GRDBTests/FTS5RecordTests.swift +++ b/Tests/GRDBTests/FTS5RecordTests.swift @@ -11,7 +11,11 @@ private struct Book { extension Book : FetchableRecord { init(row: Row) { + #if compiler(>=5.5) + id = row[.rowID] + #else id = row[Column.rowID] + #endif title = row["title"] author = row["author"] body = row["body"] @@ -21,9 +25,13 @@ extension Book : FetchableRecord { extension Book : MutablePersistableRecord { static let databaseTableName = "books" static let databaseSelection: [SQLSelectable] = [AllColumns(), Column.rowID] - + func encode(to container: inout PersistenceContainer) { + #if compiler(>=5.5) + container[.rowID] = id + #else container[Column.rowID] = id + #endif container["title"] = title container["author"] = author container["body"] = body diff --git a/Tests/GRDBTests/RecordPrimaryKeyHiddenRowIDTests.swift b/Tests/GRDBTests/RecordPrimaryKeyHiddenRowIDTests.swift index 3dbd97bca..a17f5b45a 100644 --- a/Tests/GRDBTests/RecordPrimaryKeyHiddenRowIDTests.swift +++ b/Tests/GRDBTests/RecordPrimaryKeyHiddenRowIDTests.swift @@ -36,7 +36,11 @@ private class Person : Record, Hashable { } required init(row: Row) { + #if compiler(>=5.5) + id = row[.rowID] + #else id = row[Column.rowID] + #endif age = row["age"] name = row["name"] creationDate = row["creationDate"] @@ -44,7 +48,11 @@ private class Person : Record, Hashable { } override func encode(to container: inout PersistenceContainer) { + #if compiler(>=5.5) + container[.rowID] = id + #else container[Column.rowID] = id + #endif container["name"] = name container["age"] = age container["creationDate"] = creationDate From 47934cc85899395dba76f24a3868a31303a0ef26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 22 Aug 2021 12:44:54 +0200 Subject: [PATCH 16/19] TODO --- TODO.md | 1 - 1 file changed, 1 deletion(-) diff --git a/TODO.md b/TODO.md index 6db539a64..f03eb6086 100644 --- a/TODO.md +++ b/TODO.md @@ -18,7 +18,6 @@ - [ ] Breaking: have DatabaseRegionObservation produce DatabaseCancellable just as ValueObservation. - [ ] Can Swift 5.5 help us with `select(.all)` (request of RowDecoder), `select(.id)` (request of RowDecoder.ID), `select(.rowid)` (request of Int64)? - [ ] Direct access to statement for bindings -- [ ] Breaking: make `fetchOne(key:)` type-safe (have a single dedicated primary key type) - [ ] Property wrapper that decodes dictionaries (but how to tell the key column?) - [X] See if SQLITE_FCNTL_DATA_VERSION could help working around the lack of snapshots in order to avoid double initial fetch of ValueObservation. Result: no, it does not look it returns values that are comparable between two distinct SQLite connections (from the initial reader, and from the writer thhat starts the observation) - [ ] Grab all FTS tokens in a string From 5ecc069bb44a84f79c484de294ded16fc60e1914 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 22 Aug 2021 13:34:07 +0200 Subject: [PATCH 17/19] TODO --- TODO.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/TODO.md b/TODO.md index f03eb6086..a6b4afd0f 100644 --- a/TODO.md +++ b/TODO.md @@ -36,7 +36,7 @@ - [ ] Turn a hasMany to hasOne without first/last : hasMany(Book.self).filter(Column("isBest") /* assume a single book is flagged best */).asOne() - [ ] Support for more kinds of joins: https://github.com/groue/GRDB.swift/issues/740 - [ ] HasAndBelongsToMany: https://github.com/groue/GRDB.swift/issues/711 -- [ ] Support UNION https://github.com/groue/GRDB.swift/issues/671 +- [ ] Support UNION https://github.com/groue/GRDB.swift/issues/671 (https://www.sqlite.org/lang_select.html#compound) - [ ] request.exists(db) as an alternative to fetchOne(db) != nil. Can generate optimized SQL. - [ ] Measure the duration of transactions - [ ] Improve SQL generation for `Player.....fetchCount(db)`, especially with distinct. Try to avoid `SELECT COUNT(*) FROM (SELECT DISTINCT player.* ...)` @@ -63,7 +63,6 @@ - [ ] Have SQLPrimaryKeyExpression embed the record type - [ ] Remove support for suspended databases - https://inessential.com/2020/02/13/how_we_fixed_the_dreaded_0xdead10cc_cras - [ ] https://sqlite.org/pragma.html#pragma_index_xinfo -- [ ] Deprecate DatabaseQueue/Pool.addFunction, collation, tokenizer: those should be done in Configuration.prepareDatabase - [ ] filter(rowid:), filter(rowids:) - [ ] https://github.com/apple/swift-evolution/blob/master/proposals/0075-import-test.md - [ ] https://forums.swift.org/t/how-to-encode-objects-of-unknown-type/12253/6 @@ -72,7 +71,6 @@ - [ ] Not sure: type safety for SQL expressions - [ ] Introduce some record protocol with an associated primary key type. Restrict filter(key:) methods to this type. Allow distinguishing FooId from BarId types. - [ ] Replace Column with TypedColumn. How to avoid code duplication (repeated types)? Keypaths? -- [ ] Cursor.underestimatedCount, which could speed up Array(cursor) and fetchAll() - [ ] Remove prefix from association keys when association name is namespaced: https://github.com/groue/GRDB.swift/issues/584#issuecomment-517658122 - [ ] Alternative support for custom SQLite builds, wih CocoaPods: https://github.com/CocoaPods/CocoaPods/issues/9103 From 28f2aa142356f33380a5e14e3c10160169d718d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 22 Aug 2021 15:52:45 +0200 Subject: [PATCH 18/19] Upgrade performance comparison dependencies --- .../xcshareddata/swiftpm/Package.resolved | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Tests/Performance/GRDBPerformance/GRDBPerformance.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Tests/Performance/GRDBPerformance/GRDBPerformance.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index a79b099bb..58409b93e 100644 --- a/Tests/Performance/GRDBPerformance/GRDBPerformance.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Tests/Performance/GRDBPerformance/GRDBPerformance.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -15,8 +15,8 @@ "repositoryURL": "https://github.com/realm/realm-cocoa.git", "state": { "branch": null, - "revision": "ae8e646590396dfc13c1abbf8aa2e48c43766dce", - "version": "10.7.2" + "revision": "83a07f6a508c3427058d9e2c466208d0b6a960fa", + "version": "10.12.0" } }, { @@ -24,8 +24,8 @@ "repositoryURL": "https://github.com/realm/realm-core", "state": { "branch": null, - "revision": "bab46acdca91c417a0d4849b8f4992a3c17e29a5", - "version": "10.5.5" + "revision": "e72b3078bfc5c3f69a0b18f7a220be27e28c463f", + "version": "11.2.0" } }, { @@ -33,8 +33,8 @@ "repositoryURL": "https://github.com/stephencelis/SQLite.swift.git", "state": { "branch": null, - "revision": "0a9893ec030501a3956bee572d6b4fdd3ae158a1", - "version": "0.12.2" + "revision": "8096e9b9c5cc694f373d2176f96889d3e4afe053", + "version": "0.13.0" } } ] From 04c18e3fd6b9c70f34d65953edb83742ada60b40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sun, 22 Aug 2021 15:30:41 +0200 Subject: [PATCH 19/19] v5.10.0 --- CHANGELOG.md | 6 +++-- Documentation/FullTextSearch.md | 4 ++-- Documentation/Migrations.md | 2 +- GRDB.swift.podspec | 2 +- Makefile | 6 ++--- README.md | 42 ++++++++++++++++----------------- Support/Info.plist | 2 +- 7 files changed, 33 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9850633f2..feb924eba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: #### 5.x Releases -- [Development Branch](#development-branch) +- `5.10.x` Releases - [5.10.0](#5100) - `5.9.x` Releases - [5.9.0](#590) - `5.8.x` Releases - [5.8.0](#580) - `5.7.x` Releases - [5.7.0](#570) | [5.7.1](#571) | [5.7.2](#572) | [5.7.3](#573) | [5.7.4](#574) @@ -77,7 +77,9 @@ GRDB adheres to [Semantic Versioning](https://semver.org/), with one exception: --- -## Development Branch +## 5.10.0 + +Released August 22, 2021 • [diff](https://github.com/groue/GRDB.swift/compare/v5.9.0...v5.10.0) - **New**: [#1036](https://github.com/groue/GRDB.swift/pull/1036) by [@groue](https://github.com/groue): Restore minimal CI tests - **New**: [#1037](https://github.com/groue/GRDB.swift/pull/1037) by [@groue](https://github.com/groue): Support BUILD_LIBRARY_FOR_DISTRIBUTION diff --git a/Documentation/FullTextSearch.md b/Documentation/FullTextSearch.md index 13c496dee..e6c3102eb 100644 --- a/Documentation/FullTextSearch.md +++ b/Documentation/FullTextSearch.md @@ -280,7 +280,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.9/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.10/Structs/StatementArguments.html): ```swift let documents = try Document.fetchAll(db, @@ -529,7 +529,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.9/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.10/Structs/StatementArguments.html): ```swift let documents = try Document.fetchAll(db, diff --git a/Documentation/Migrations.md b/Documentation/Migrations.md index 1dec073ad..443060e04 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.9/Structs/DatabaseMigrator.html) for more migrator methods. +See the [DatabaseMigrator reference](http://groue.github.io/GRDB.swift/docs/5.10/Structs/DatabaseMigrator.html) for more migrator methods. ## The `eraseDatabaseOnSchemaChange` Option diff --git a/GRDB.swift.podspec b/GRDB.swift.podspec index abc173109..ed4f2de29 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.9.0' + s.version = '5.10.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 fd253ecd6..f318cc212 100644 --- a/Makefile +++ b/Makefile @@ -438,10 +438,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.9.0 \ - --module-version 5.9.0 \ + --github-file-prefix https://github.com/groue/GRDB.swift/tree/v5.10.0 \ + --module-version 5.10.0 \ --module GRDB \ - --root-url http://groue.github.io/GRDB.swift/docs/5.9/ \ + --root-url http://groue.github.io/GRDB.swift/docs/5.10/ \ --output Documentation/Reference \ --xcodebuild-arguments -project,GRDB.xcodeproj,-scheme,GRDBiOS else diff --git a/README.md b/README.md index c3627c5d1..ae8436b04 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,13 @@ --- -**Latest release**: August 15, 2021 • version 5.9.0 • [CHANGELOG](CHANGELOG.md) • [Migrating From GRDB 4 to GRDB 5](Documentation/GRDB5MigrationGuide.md) +**Latest release**: August 22, 2021 • version 5.10.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+ | Swift version | GRDB version | | -------------- | ----------------------------------------------------------- | -| **Swift 5.2+** | **v5.9.0** | +| **Swift 5.2+** | **v5.10.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.9/index.html) (generated by [Jazzy](https://github.com/realm/jazzy)) +- [GRDB Reference](http://groue.github.io/GRDB.swift/docs/5.10/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.9/Structs/Configuration.html) for more details. +See [Configuration](http://groue.github.io/GRDB.swift/docs/5.10/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.9/Structs/Configuration.html) for more details. +See [Configuration](http://groue.github.io/GRDB.swift/docs/5.10/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.9/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.10/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.9/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.10/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.9/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.10/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.9/Structs/StatementArguments.html): +Values can be used as [statement arguments](http://groue.github.io/GRDB.swift/docs/5.10/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.9/Structs/Configuration.html) configuration flag: +Transactions can't be left opened unless you set the [allowsUnsafeTransactions](http://groue.github.io/GRDB.swift/docs/5.10/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.9/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.10/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.9/Classes/Statement.html). +For more information about prepared statements, see the [Statement reference](http://groue.github.io/GRDB.swift/docs/5.10/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.9/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.10/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()`. @@ -3093,7 +3093,7 @@ protocol EncodableRecord { } ``` -See [DatabaseDateDecodingStrategy](https://groue.github.io/GRDB.swift/docs/5.9/Enums/DatabaseDateDecodingStrategy.html), [DatabaseDateEncodingStrategy](https://groue.github.io/GRDB.swift/docs/5.9/Enums/DatabaseDateEncodingStrategy.html), and [DatabaseUUIDEncodingStrategy](https://groue.github.io/GRDB.swift/docs/5.9/Enums/DatabaseUUIDEncodingStrategy.html) to learn about all available strategies. +See [DatabaseDateDecodingStrategy](https://groue.github.io/GRDB.swift/docs/5.10/Enums/DatabaseDateDecodingStrategy.html), [DatabaseDateEncodingStrategy](https://groue.github.io/GRDB.swift/docs/5.10/Enums/DatabaseDateEncodingStrategy.html), and [DatabaseUUIDEncodingStrategy](https://groue.github.io/GRDB.swift/docs/5.10/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). @@ -4623,7 +4623,7 @@ Player // SELECT * FROM player ``` -Raw SQL snippets are also accepted, with eventual [arguments](http://groue.github.io/GRDB.swift/docs/5.9/Structs/StatementArguments.html): +Raw SQL snippets are also accepted, with eventual [arguments](http://groue.github.io/GRDB.swift/docs/5.10/Structs/StatementArguments.html): ```swift // SELECT DATE(creationDate), COUNT(*) FROM player WHERE name = 'Arthur' GROUP BY date(creationDate) @@ -5342,7 +5342,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.9/Structs/AnyFetchRequest.html): a type-erased request. +- [AnyFetchRequest](http://groue.github.io/GRDB.swift/docs/5.10/Structs/AnyFetchRequest.html): a type-erased request. ## Joined Queries Support @@ -6520,7 +6520,7 @@ After `stopObservingDatabaseChangesUntilNextTransaction()`, the `databaseDidChan ### DatabaseRegion -**[DatabaseRegion](https://groue.github.io/GRDB.swift/docs/5.9/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.10/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. @@ -6530,7 +6530,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.9/Structs/DatabaseRegion.html#/s:4GRDB14DatabaseRegionV10isModified2bySbAA0B5EventV_tF). +For more details, see the [reference](http://groue.github.io/GRDB.swift/docs/5.10/Structs/DatabaseRegion.html#/s:4GRDB14DatabaseRegionV10isModified2bySbAA0B5EventV_tF). #### The DatabaseRegionConvertible Protocol @@ -7650,7 +7650,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.9/Protocols/DatabaseReader.html) and [DatabaseWriter](http://groue.github.io/GRDB.swift/docs/5.9/Protocols/DatabaseWriter.html) protocols. DatabaseSnapshot adopts DatabaseReader only. +Both DatabaseQueue and DatabasePool adopt the [DatabaseReader](http://groue.github.io/GRDB.swift/docs/5.10/Protocols/DatabaseReader.html) and [DatabaseWriter](http://groue.github.io/GRDB.swift/docs/5.10/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: @@ -8331,7 +8331,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.9/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.10/Structs/Configuration.html#/s:4GRDB13ConfigurationV33acceptsDoubleQuotedStringLiteralsSbvp). @@ -8498,7 +8498,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.9/Structs/SQLRequest.html +[SQLRequest]: http://groue.github.io/GRDB.swift/docs/5.10/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 b259696f0..d287ed0ab 100644 --- a/Support/Info.plist +++ b/Support/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 5.9.0 + 5.10.0 CFBundleSignature ???? CFBundleVersion