diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index 4620dfcb7..edf239aec 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -11,7 +11,7 @@ import Foundation public typealias SQLiteConnection = OpaquePointer /// A raw SQLite function argument. -@usableFromInline typealias SQLiteValue = OpaquePointer +typealias SQLiteValue = OpaquePointer let SQLITE_TRANSIENT = unsafeBitCast(OpaquePointer(bitPattern: -1), to: sqlite3_destructor_type.self) diff --git a/GRDB/Core/DatabaseValue.swift b/GRDB/Core/DatabaseValue.swift index 1adaea701..d2b44f81e 100644 --- a/GRDB/Core/DatabaseValue.swift +++ b/GRDB/Core/DatabaseValue.swift @@ -98,7 +98,6 @@ public struct DatabaseValue: Hashable, CustomStringConvertible, DatabaseValueCon } // SQLite function argument - @usableFromInline init(sqliteValue: SQLiteValue) { switch sqlite3_value_type(sqliteValue) { case SQLITE_NULL: @@ -123,7 +122,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: diff --git a/GRDB/Core/DatabaseValueConversion.swift b/GRDB/Core/DatabaseValueConversion.swift index 5c8930d72..a752e34e5 100644 --- a/GRDB/Core/DatabaseValueConversion.swift +++ b/GRDB/Core/DatabaseValueConversion.swift @@ -162,7 +162,7 @@ func fatalConversionError(to: T.Type, from dbValue: DatabaseValue?, sqliteSta /// Lossless conversions from database values and rows extension DatabaseValueConvertible { - @inlinable + @usableFromInline static func decode(from sqliteStatement: SQLiteStatement, atUncheckedIndex index: Int32) -> Self { let dbValue = DatabaseValue(sqliteStatement: sqliteStatement, index: index) if let value = fromDatabaseValue(dbValue) { @@ -187,7 +187,7 @@ extension DatabaseValueConvertible { conversionContext: ValueConversionContext(row).atColumn(index)) } - @inlinable + @usableFromInline static func decodeIfPresent(from sqliteStatement: SQLiteStatement, atUncheckedIndex index: Int32) -> Self? { let dbValue = DatabaseValue(sqliteStatement: sqliteStatement, index: index) if let value = fromDatabaseValue(dbValue) { diff --git a/GRDB/Core/DatabaseValueConvertible.swift b/GRDB/Core/DatabaseValueConvertible.swift index f62975edf..3c0095e4b 100644 --- a/GRDB/Core/DatabaseValueConvertible.swift +++ b/GRDB/Core/DatabaseValueConvertible.swift @@ -55,7 +55,6 @@ public final class DatabaseValueCursor : Cursor @usableFromInline let _columnIndex: Int32 @usableFromInline var _done = false - @inlinable init(statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws { _statement = statement _sqliteStatement = statement.sqliteStatement @@ -109,7 +108,6 @@ public final class NullableDatabaseValueCursor @usableFromInline let _columnIndex: Int32 @usableFromInline var _done = false - @inlinable init(statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws { _statement = statement _sqliteStatement = statement.sqliteStatement @@ -184,7 +182,6 @@ extension DatabaseValueConvertible { /// - adapter: Optional RowAdapter /// - returns: A cursor over fetched values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchCursor(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> DatabaseValueCursor { return try DatabaseValueCursor(statement: statement, arguments: arguments, adapter: adapter) } @@ -200,7 +197,6 @@ extension DatabaseValueConvertible { /// - adapter: Optional RowAdapter /// - returns: An array. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchAll(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Self] { return try Array(fetchCursor(statement, arguments: arguments, adapter: adapter)) } @@ -219,7 +215,6 @@ extension DatabaseValueConvertible { /// - adapter: Optional RowAdapter /// - returns: An optional value. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchOne(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self? { // fetchOne returns nil if there is no row, or if there is a row with a null value let cursor = try NullableDatabaseValueCursor(statement: statement, arguments: arguments, adapter: adapter) @@ -250,7 +245,6 @@ extension DatabaseValueConvertible { /// - adapter: Optional RowAdapter /// - returns: A cursor over fetched values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> DatabaseValueCursor { return try fetchCursor(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } @@ -266,7 +260,6 @@ extension DatabaseValueConvertible { /// - adapter: Optional RowAdapter /// - returns: An array. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Self] { return try fetchAll(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } @@ -285,7 +278,6 @@ extension DatabaseValueConvertible { /// - adapter: Optional RowAdapter /// - returns: An optional value. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchOne(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Self? { return try fetchOne(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } @@ -313,7 +305,6 @@ extension DatabaseValueConvertible { /// - request: A FetchRequest. /// - returns: A cursor over fetched values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchCursor(_ db: Database, _ request: R) throws -> DatabaseValueCursor { let (statement, adapter) = try request.prepare(db, forSingleResult: false) return try fetchCursor(statement, adapter: adapter) @@ -329,7 +320,6 @@ extension DatabaseValueConvertible { /// - request: A FetchRequest. /// - returns: An array. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchAll(_ db: Database, _ request: R) throws -> [Self] { let (statement, adapter) = try request.prepare(db, forSingleResult: false) return try fetchAll(statement, adapter: adapter) @@ -348,7 +338,6 @@ extension DatabaseValueConvertible { /// - request: A FetchRequest. /// - returns: An optional value. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchOne(_ db: Database, _ request: R) throws -> Self? { let (statement, adapter) = try request.prepare(db, forSingleResult: true) return try fetchOne(statement, adapter: adapter) @@ -375,7 +364,6 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible { /// - parameter db: A database connection. /// - returns: A cursor over fetched values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public func fetchCursor(_ db: Database) throws -> DatabaseValueCursor { return try RowDecoder.fetchCursor(db, self) } @@ -388,7 +376,6 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible { /// - parameter db: A database connection. /// - returns: An array of values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public func fetchAll(_ db: Database) throws -> [RowDecoder] { return try RowDecoder.fetchAll(db, self) } @@ -404,7 +391,6 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible { /// - parameter db: A database connection. /// - returns: An optional value. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public func fetchOne(_ db: Database) throws -> RowDecoder? { return try RowDecoder.fetchOne(db, self) } @@ -444,7 +430,6 @@ extension Optional where Wrapped: DatabaseValueConvertible { /// - adapter: Optional RowAdapter /// - returns: A cursor over fetched optional values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchCursor(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> NullableDatabaseValueCursor { return try NullableDatabaseValueCursor(statement: statement, arguments: arguments, adapter: adapter) } @@ -460,7 +445,6 @@ extension Optional where Wrapped: DatabaseValueConvertible { /// - adapter: Optional RowAdapter /// - returns: An array of optional values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchAll(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Wrapped?] { return try Array(fetchCursor(statement, arguments: arguments, adapter: adapter)) } @@ -489,7 +473,6 @@ extension Optional where Wrapped: DatabaseValueConvertible { /// - adapter: Optional RowAdapter /// - returns: A cursor over fetched optional values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> NullableDatabaseValueCursor { return try fetchCursor(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } @@ -505,7 +488,6 @@ extension Optional where Wrapped: DatabaseValueConvertible { /// - adapter: Optional RowAdapter /// - returns: An array of optional values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Wrapped?] { return try fetchAll(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } @@ -533,7 +515,6 @@ extension Optional where Wrapped: DatabaseValueConvertible { /// - request: A FetchRequest. /// - returns: A cursor over fetched optional values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchCursor(_ db: Database, _ request: R) throws -> NullableDatabaseValueCursor { let (statement, adapter) = try request.prepare(db, forSingleResult: false) return try fetchCursor(statement, adapter: adapter) @@ -549,7 +530,6 @@ extension Optional where Wrapped: DatabaseValueConvertible { /// - request: A FetchRequest. /// - returns: An array of optional values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchAll(_ db: Database, _ request: R) throws -> [Wrapped?] { let (statement, adapter) = try request.prepare(db, forSingleResult: false) return try fetchAll(statement, adapter: adapter) @@ -576,7 +556,6 @@ extension FetchRequest where RowDecoder: _OptionalProtocol, RowDecoder._Wrapped: /// - parameter db: A database connection. /// - returns: A cursor over fetched values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public func fetchCursor(_ db: Database) throws -> NullableDatabaseValueCursor { return try Optional.fetchCursor(db, self) } @@ -589,7 +568,6 @@ extension FetchRequest where RowDecoder: _OptionalProtocol, RowDecoder._Wrapped: /// - parameter db: A database connection. /// - returns: An array of values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public func fetchAll(_ db: Database) throws -> [RowDecoder._Wrapped?] { return try Optional.fetchAll(db, self) } diff --git a/GRDB/Core/Row.swift b/GRDB/Core/Row.swift index 9c94b4db0..c204fdeee 100644 --- a/GRDB/Core/Row.swift +++ b/GRDB/Core/Row.swift @@ -103,7 +103,6 @@ public final class Row : Equatable, Hashable, RandomAccessCollection, Expressibl /// The row is implemented on top of StatementRowImpl, which grants *direct* /// access to the SQLite statement. Iteration of the statement does modify /// the row. - @usableFromInline init(statement: SelectStatement) { let statementRef = Unmanaged.passRetained(statement) // released in deinit self.statementRef = statementRef @@ -768,7 +767,6 @@ public final class RowCursor : Cursor { @usableFromInline let _row: Row // Reused for performance @usableFromInline var _done = false - @inlinable init(statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws { self.statement = statement self._row = try Row(statement: statement).adapted(with: adapter, layout: statement) @@ -835,7 +833,6 @@ extension Row { /// - adapter: Optional RowAdapter /// - returns: A cursor over fetched rows. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchCursor(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> RowCursor { return try RowCursor(statement: statement, arguments: arguments, adapter: adapter) } @@ -851,7 +848,6 @@ extension Row { /// - adapter: Optional RowAdapter /// - returns: An array of rows. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchAll(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Row] { // The cursor reuses a single mutable row. Return immutable copies. return try Array(fetchCursor(statement, arguments: arguments, adapter: adapter).map { $0.copy() }) @@ -868,7 +864,6 @@ extension Row { /// - adapter: Optional RowAdapter /// - returns: An optional row. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchOne(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Row? { let cursor = try fetchCursor(statement, arguments: arguments, adapter: adapter) // Keep cursor alive until we can copy the fetched row @@ -910,7 +905,6 @@ extension Row { /// - adapter: Optional RowAdapter /// - returns: A cursor over fetched rows. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> RowCursor { return try fetchCursor(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } @@ -930,7 +924,6 @@ extension Row { /// - adapter: Optional RowAdapter /// - returns: An array of rows. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Row] { return try fetchAll(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } @@ -950,7 +943,6 @@ extension Row { /// - adapter: Optional RowAdapter /// - returns: An optional row. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchOne(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Row? { return try fetchOne(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } @@ -987,7 +979,6 @@ extension Row { /// - request: A FetchRequest. /// - returns: A cursor over fetched rows. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchCursor(_ db: Database, _ request: R) throws -> RowCursor { let (statement, adapter) = try request.prepare(db, forSingleResult: false) return try fetchCursor(statement, adapter: adapter) @@ -1003,7 +994,6 @@ extension Row { /// - request: A FetchRequest. /// - returns: An array of rows. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchAll(_ db: Database, _ request: R) throws -> [Row] { let (statement, adapter) = try request.prepare(db, forSingleResult: false) return try fetchAll(statement, adapter: adapter) @@ -1019,7 +1009,6 @@ extension Row { /// - request: A FetchRequest. /// - returns: An optional row. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchOne(_ db: Database, _ request: R) throws -> Row? { let (statement, adapter) = try request.prepare(db, forSingleResult: true) return try fetchOne(statement, adapter: adapter) @@ -1055,7 +1044,6 @@ extension FetchRequest where RowDecoder == Row { /// - parameter db: A database connection. /// - returns: A cursor over fetched rows. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public func fetchCursor(_ db: Database) throws -> RowCursor { return try Row.fetchCursor(db, self) } @@ -1068,7 +1056,6 @@ extension FetchRequest where RowDecoder == Row { /// - parameter db: A database connection. /// - returns: An array of fetched rows. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public func fetchAll(_ db: Database) throws -> [Row] { return try Row.fetchAll(db, self) } @@ -1081,7 +1068,6 @@ extension FetchRequest where RowDecoder == Row { /// - parameter db: A database connection. /// - returns: An optional row. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public func fetchOne(_ db: Database) throws -> Row? { return try Row.fetchOne(db, self) } diff --git a/GRDB/Core/RowAdapter.swift b/GRDB/Core/RowAdapter.swift index 24b675d47..b9ab95c8c 100644 --- a/GRDB/Core/RowAdapter.swift +++ b/GRDB/Core/RowAdapter.swift @@ -246,7 +246,6 @@ extension RowAdapter { } extension RowAdapter { - @usableFromInline func baseColumnIndex(atIndex index: Int, layout: RowLayout) throws -> Int { return try layoutedAdapter(from: layout).mapping.baseColumnIndex(atMappingIndex: index) } @@ -461,7 +460,6 @@ extension Row { } /// Returns self if adapter is nil - @usableFromInline func adapted(with adapter: RowAdapter?, layout: RowLayout) throws -> Row { guard let adapter = adapter else { return self diff --git a/GRDB/Core/Statement.swift b/GRDB/Core/Statement.swift index 6218cdc16..73a76d472 100644 --- a/GRDB/Core/Statement.swift +++ b/GRDB/Core/Statement.swift @@ -339,7 +339,6 @@ public final class SelectStatement : Statement { } /// Utility function for cursors - @usableFromInline func reset(withArguments arguments: StatementArguments? = nil) { prepare(withArguments: arguments) try! reset() @@ -369,12 +368,11 @@ public final class SelectStatement : Statement { /// try cursor.next() /// } final class StatementCursor: Cursor { - @usableFromInline let _statement: SelectStatement - @usableFromInline let _sqliteStatement: SQLiteStatement - @usableFromInline var _done = false + let _statement: SelectStatement + let _sqliteStatement: SQLiteStatement + var _done = false // Use SelectStatement.makeCursor() instead - @inlinable init(statement: SelectStatement, arguments: StatementArguments? = nil) { _statement = statement _sqliteStatement = statement.sqliteStatement diff --git a/GRDB/Core/StatementColumnConvertible.swift b/GRDB/Core/StatementColumnConvertible.swift index b7ec37d71..f0a03fac6 100644 --- a/GRDB/Core/StatementColumnConvertible.swift +++ b/GRDB/Core/StatementColumnConvertible.swift @@ -67,7 +67,6 @@ public final class FastDatabaseValueCursor FastDatabaseValueCursor { return try FastDatabaseValueCursor(statement: statement, arguments: arguments, adapter: adapter) } @@ -205,7 +202,6 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { /// - adapter: Optional RowAdapter /// - returns: An array of values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchAll(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Self] { return try Array(fetchCursor(statement, arguments: arguments, adapter: adapter)) } @@ -221,7 +217,6 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { /// - adapter: Optional RowAdapter /// - returns: An optional value. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchOne(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self? { // fetchOne returns nil if there is no row, or if there is a row with a null value let cursor = try FastNullableDatabaseValueCursor(statement: statement, arguments: arguments, adapter: adapter) @@ -252,7 +247,6 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { /// - adapter: Optional RowAdapter /// - returns: A cursor over fetched values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> FastDatabaseValueCursor { return try fetchCursor(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } @@ -268,7 +262,6 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { /// - adapter: Optional RowAdapter /// - returns: An array of values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Self] { return try fetchAll(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } @@ -284,7 +277,6 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { /// - adapter: Optional RowAdapter /// - returns: An optional value. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchOne(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Self? { return try fetchOne(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } @@ -312,7 +304,6 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { /// - request: A FetchRequest. /// - returns: A cursor over fetched values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchCursor(_ db: Database, _ request: R) throws -> FastDatabaseValueCursor { let (statement, adapter) = try request.prepare(db, forSingleResult: false) return try fetchCursor(statement, adapter: adapter) @@ -328,7 +319,6 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { /// - request: A FetchRequest. /// - returns: An array of values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchAll(_ db: Database, _ request: R) throws -> [Self] { let (statement, adapter) = try request.prepare(db, forSingleResult: false) return try fetchAll(statement, adapter: adapter) @@ -344,7 +334,6 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible { /// - request: A FetchRequest. /// - returns: An optional value. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchOne(_ db: Database, _ request: R) throws -> Self? { let (statement, adapter) = try request.prepare(db, forSingleResult: true) return try fetchOne(statement, adapter: adapter) @@ -371,7 +360,6 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible & StatementCol /// - parameter db: A database connection. /// - returns: A cursor over fetched values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public func fetchCursor(_ db: Database) throws -> FastDatabaseValueCursor { return try RowDecoder.fetchCursor(db, self) } @@ -384,7 +372,6 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible & StatementCol /// - parameter db: A database connection. /// - returns: An array of values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public func fetchAll(_ db: Database) throws -> [RowDecoder] { return try RowDecoder.fetchAll(db, self) } @@ -400,7 +387,6 @@ extension FetchRequest where RowDecoder: DatabaseValueConvertible & StatementCol /// - parameter db: A database connection. /// - returns: An optional value. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public func fetchOne(_ db: Database) throws -> RowDecoder? { return try RowDecoder.fetchOne(db, self) } @@ -440,7 +426,6 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv /// - adapter: Optional RowAdapter /// - returns: A cursor over fetched optional values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchCursor(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> FastNullableDatabaseValueCursor { return try FastNullableDatabaseValueCursor(statement: statement, arguments: arguments, adapter: adapter) } @@ -456,7 +441,6 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv /// - adapter: Optional RowAdapter /// - returns: An array of optional values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchAll(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Wrapped?] { return try Array(fetchCursor(statement, arguments: arguments, adapter: adapter)) } @@ -485,7 +469,6 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv /// - adapter: Optional RowAdapter /// - returns: A cursor over fetched optional values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> FastNullableDatabaseValueCursor { return try fetchCursor(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } @@ -501,7 +484,6 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv /// - adapter: Optional RowAdapter /// - returns: An array of optional values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Wrapped?] { return try fetchAll(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } @@ -529,7 +511,6 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv /// - request: A FetchRequest. /// - returns: A cursor over fetched optional values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchCursor(_ db: Database, _ request: R) throws -> FastNullableDatabaseValueCursor { let (statement, adapter) = try request.prepare(db, forSingleResult: false) return try fetchCursor(statement, adapter: adapter) @@ -545,7 +526,6 @@ extension Optional where Wrapped: DatabaseValueConvertible & StatementColumnConv /// - request: A FetchRequest. /// - returns: An array of optional values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchAll(_ db: Database, _ request: R) throws -> [Wrapped?] { let (statement, adapter) = try request.prepare(db, forSingleResult: false) return try fetchAll(statement, adapter: adapter) @@ -572,7 +552,6 @@ extension FetchRequest where RowDecoder: _OptionalProtocol, RowDecoder._Wrapped: /// - parameter db: A database connection. /// - returns: A cursor over fetched values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public func fetchCursor(_ db: Database) throws -> FastNullableDatabaseValueCursor { return try Optional.fetchCursor(db, self) } @@ -585,7 +564,6 @@ extension FetchRequest where RowDecoder: _OptionalProtocol, RowDecoder._Wrapped: /// - parameter db: A database connection. /// - returns: An array of values. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public func fetchAll(_ db: Database) throws -> [RowDecoder._Wrapped?] { return try Optional.fetchAll(db, self) } diff --git a/GRDB/Record/FetchableRecord+TableRecord.swift b/GRDB/Record/FetchableRecord+TableRecord.swift index 91fad6b2c..937736486 100644 --- a/GRDB/Record/FetchableRecord+TableRecord.swift +++ b/GRDB/Record/FetchableRecord+TableRecord.swift @@ -24,7 +24,6 @@ extension FetchableRecord where Self: TableRecord { /// - parameter db: A database connection. /// - returns: A cursor over fetched records. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchCursor(_ db: Database) throws -> RecordCursor { return try all().fetchCursor(db) } @@ -40,7 +39,6 @@ extension FetchableRecord where Self: TableRecord { /// /// - parameter db: A database connection. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchAll(_ db: Database) throws -> [Self] { return try all().fetchAll(db) } @@ -56,7 +54,6 @@ extension FetchableRecord where Self: TableRecord { /// /// - parameter db: A database connection. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchOne(_ db: Database) throws -> Self? { return try all().fetchOne(db) } @@ -80,7 +77,6 @@ extension FetchableRecord where Self: TableRecord { /// - keys: A sequence of primary keys. /// - returns: A cursor over fetched records. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchCursor(_ db: Database, keys: Sequence) throws -> RecordCursor where Sequence.Element: DatabaseValueConvertible { return try filter(keys: keys).fetchCursor(db) } @@ -96,7 +92,6 @@ extension FetchableRecord where Self: TableRecord { /// - keys: A sequence of primary keys. /// - returns: An array of records. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchAll(_ db: Database, keys: Sequence) throws -> [Self] where Sequence.Element: DatabaseValueConvertible { let keys = Array(keys) if keys.isEmpty { @@ -115,7 +110,6 @@ extension FetchableRecord where Self: TableRecord { /// - key: A primary key value. /// - returns: An optional record. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchOne(_ db: Database, key: PrimaryKeyType?) throws -> Self? { guard let key = key else { // Avoid hitting the database @@ -144,7 +138,6 @@ extension FetchableRecord where Self: TableRecord { /// - keys: An array of key dictionaries. /// - returns: A cursor over fetched records. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchCursor(_ db: Database, keys: [[String: DatabaseValueConvertible?]]) throws -> RecordCursor { return try filter(keys: keys).fetchCursor(db) } @@ -161,7 +154,6 @@ extension FetchableRecord where Self: TableRecord { /// - keys: An array of key dictionaries. /// - returns: An array of records. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchAll(_ db: Database, keys: [[String: DatabaseValueConvertible?]]) throws -> [Self] { if keys.isEmpty { // Avoid hitting the database @@ -180,7 +172,6 @@ extension FetchableRecord where Self: TableRecord { /// - key: A dictionary of values. /// - returns: An optional record. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchOne(_ db: Database, key: [String: DatabaseValueConvertible?]?) throws -> Self? { guard let key = key else { // Avoid hitting the database diff --git a/GRDB/Record/FetchableRecord.swift b/GRDB/Record/FetchableRecord.swift index ffde74ec0..da3f35872 100644 --- a/GRDB/Record/FetchableRecord.swift +++ b/GRDB/Record/FetchableRecord.swift @@ -160,7 +160,6 @@ extension FetchableRecord { /// - adapter: Optional RowAdapter /// - returns: A cursor over fetched records. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchCursor(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> RecordCursor { return try RecordCursor(statement: statement, arguments: arguments, adapter: adapter) } @@ -176,7 +175,6 @@ extension FetchableRecord { /// - adapter: Optional RowAdapter /// - returns: An array of records. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchAll(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> [Self] { return try Array(fetchCursor(statement, arguments: arguments, adapter: adapter)) } @@ -192,7 +190,6 @@ extension FetchableRecord { /// - adapter: Optional RowAdapter /// - returns: An optional record. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchOne(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws -> Self? { return try fetchCursor(statement, arguments: arguments, adapter: adapter).next() } @@ -221,7 +218,6 @@ extension FetchableRecord { /// - adapter: Optional RowAdapter /// - returns: A cursor over fetched records. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchCursor(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> RecordCursor { return try fetchCursor(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } @@ -237,7 +233,6 @@ extension FetchableRecord { /// - adapter: Optional RowAdapter /// - returns: An array of records. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchAll(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> [Self] { return try fetchAll(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } @@ -253,7 +248,6 @@ extension FetchableRecord { /// - adapter: Optional RowAdapter /// - returns: An optional record. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchOne(_ db: Database, sql: String, arguments: StatementArguments = StatementArguments(), adapter: RowAdapter? = nil) throws -> Self? { return try fetchOne(db, SQLRequest(sql: sql, arguments: arguments, adapter: adapter)) } @@ -281,7 +275,6 @@ extension FetchableRecord { /// - sql: a FetchRequest. /// - returns: A cursor over fetched records. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchCursor(_ db: Database, _ request: R) throws -> RecordCursor { let (statement, adapter) = try request.prepare(db, forSingleResult: false) return try fetchCursor(statement, adapter: adapter) @@ -297,7 +290,6 @@ extension FetchableRecord { /// - sql: a FetchRequest. /// - returns: An array of records. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchAll(_ db: Database, _ request: R) throws -> [Self] { let (statement, adapter) = try request.prepare(db, forSingleResult: false) return try fetchAll(statement, adapter: adapter) @@ -313,7 +305,6 @@ extension FetchableRecord { /// - sql: a FetchRequest. /// - returns: An optional record. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public static func fetchOne(_ db: Database, _ request: R) throws -> Self? { let (statement, adapter) = try request.prepare(db, forSingleResult: true) return try fetchOne(statement, adapter: adapter) @@ -342,7 +333,6 @@ extension FetchRequest where RowDecoder: FetchableRecord { /// - parameter db: A database connection. /// - returns: A cursor over fetched records. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public func fetchCursor(_ db: Database) throws -> RecordCursor { return try RowDecoder.fetchCursor(db, self) } @@ -355,7 +345,6 @@ extension FetchRequest where RowDecoder: FetchableRecord { /// - parameter db: A database connection. /// - returns: An array of records. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public func fetchAll(_ db: Database) throws -> [RowDecoder] { return try RowDecoder.fetchAll(db, self) } @@ -368,7 +357,6 @@ extension FetchRequest where RowDecoder: FetchableRecord { /// - parameter db: A database connection. /// - returns: An optional record. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. - @inlinable public func fetchOne(_ db: Database) throws -> RowDecoder? { return try RowDecoder.fetchOne(db, self) } @@ -388,7 +376,6 @@ public final class RecordCursor : Cursor { @usableFromInline let _sqliteStatement: SQLiteStatement @usableFromInline var _done = false - @inlinable init(statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) throws { _statement = statement _row = try Row(statement: statement).adapted(with: adapter, layout: statement) diff --git a/GRDB/Utils/OrderedDictionary.swift b/GRDB/Utils/OrderedDictionary.swift index 0203e0fcb..dd51231c8 100644 --- a/GRDB/Utils/OrderedDictionary.swift +++ b/GRDB/Utils/OrderedDictionary.swift @@ -31,7 +31,7 @@ struct OrderedDictionary { } /// Returns the value associated with key, or nil. - @inlinable + @usableFromInline subscript(_ key: Key) -> Value? { get { return dictionary[key] } set { @@ -68,7 +68,7 @@ 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 - @inlinable + @usableFromInline mutating func updateValue(_ value: Value, forKey key: Key) -> Value? { if let oldValue = dictionary.updateValue(value, forKey: key) { return oldValue @@ -79,7 +79,7 @@ struct OrderedDictionary { /// Removes the value associated with key. @discardableResult - @usableFromInline + @inlinable mutating func removeValue(forKey key: Key) -> Value? { guard let value = dictionary.removeValue(forKey: key) else { return nil