diff --git a/GRDB/Core/DatabaseValueConversion.swift b/GRDB/Core/DatabaseValueConversion.swift index 05d530b94..4c25c246f 100644 --- a/GRDB/Core/DatabaseValueConversion.swift +++ b/GRDB/Core/DatabaseValueConversion.swift @@ -26,7 +26,7 @@ struct ValueConversionContext: Refinable { case .columnIndex(let index): return index case .columnName(let name): - return row?.index(ofColumn: name) + return row?.index(forColumn: name) } } diff --git a/GRDB/Core/Row.swift b/GRDB/Core/Row.swift index 256e9dbfc..73265a18b 100644 --- a/GRDB/Core/Row.swift +++ b/GRDB/Core/Row.swift @@ -140,12 +140,12 @@ extension Row { /// /// This method is case-insensitive. public func hasColumn(_ columnName: String) -> Bool { - index(ofColumn: columnName) != nil + index(forColumn: columnName) != nil } @usableFromInline - func index(ofColumn name: String) -> Int? { - impl.index(ofColumn: name) + func index(forColumn name: String) -> Int? { + impl.index(forColumn: name) } } @@ -282,7 +282,7 @@ extension Row { // if row["foo"] != nil { ... } // // Without this method, the code above would not compile. - guard let index = index(ofColumn: columnName) else { + guard let index = index(forColumn: columnName) else { return nil } return impl.databaseValue(atUncheckedIndex: index).storage.value @@ -298,7 +298,7 @@ extension Row { /// `Value`. Should this conversion fail, a fatal error is raised. @inlinable public subscript(_ columnName: String) -> Value? { - guard let index = index(ofColumn: columnName) else { + guard let index = index(forColumn: columnName) else { return nil } return Value.decodeIfPresent(from: self, atUncheckedIndex: index) @@ -318,7 +318,7 @@ extension Row { /// (see https://www.sqlite.org/datatype3.html). @inlinable public subscript(_ columnName: String) -> Value? { - guard let index = index(ofColumn: columnName) else { + guard let index = index(forColumn: columnName) else { return nil } return Value.fastDecodeIfPresent(from: self, atUncheckedIndex: index) @@ -335,7 +335,7 @@ extension Row { /// SQLite value can not be converted to `Value`. @inlinable public subscript(_ columnName: String) -> Value { - guard let index = index(ofColumn: columnName) else { + guard let index = index(forColumn: columnName) else { // No such column fatalConversionError(to: Value.self, from: nil, in: self, atColumn: columnName) } @@ -357,7 +357,7 @@ extension Row { /// (see https://www.sqlite.org/datatype3.html). @inlinable public subscript(_ columnName: String) -> Value { - guard let index = index(ofColumn: columnName) else { + guard let index = index(forColumn: columnName) else { // No such column fatalConversionError(to: Value.self, from: nil, in: self, atColumn: columnName) } @@ -475,7 +475,7 @@ extension Row { /// The returned data does not owns its bytes: it must not be used longer /// than the row's lifetime. public func dataNoCopy(named columnName: String) -> Data? { - guard let index = index(ofColumn: columnName) else { + guard let index = index(forColumn: columnName) else { return nil } return impl.dataNoCopy(atUncheckedIndex: index) @@ -1582,7 +1582,7 @@ protocol RowImpl { func dataNoCopy(atUncheckedIndex index: Int) -> Data? /// Returns the index of the leftmost column that matches *name* (case-insensitive) - func index(ofColumn name: String) -> Int? + func index(forColumn name: String) -> Int? // row.impl is guaranteed to be self. func unscopedRow(_ row: Row) -> Row @@ -1665,7 +1665,7 @@ private struct ArrayRowImpl: RowImpl { columns[index].0 } - func index(ofColumn name: String) -> Int? { + func index(forColumn name: String) -> Int? { let lowercaseName = name.lowercased() return columns.firstIndex { (column, _) in column.lowercased() == lowercaseName } } @@ -1703,7 +1703,7 @@ private struct StatementCopyRowImpl: RowImpl { columnNames[index] } - func index(ofColumn name: String) -> Int? { + func index(forColumn name: String) -> Int? { let lowercaseName = name.lowercased() return columnNames.firstIndex { $0.lowercased() == lowercaseName } } @@ -1777,7 +1777,7 @@ private struct StatementRowImpl: RowImpl { statement.columnNames[index] } - func index(ofColumn name: String) -> Int? { + func index(forColumn name: String) -> Int? { if let index = lowercaseColumnIndexes[name] { return index } @@ -1814,7 +1814,7 @@ private struct SQLiteStatementRowImpl: RowImpl { return Data(bytesNoCopy: UnsafeMutableRawPointer(mutating: bytes), count: count, deallocator: .none) } - func index(ofColumn name: String) -> Int? { + func index(forColumn name: String) -> Int? { let name = name.lowercased() for index in 0.. Int? { nil } + func index(forColumn name: String) -> Int? { nil } func copiedRow(_ row: Row) -> Row { row } } diff --git a/GRDB/Core/RowAdapter.swift b/GRDB/Core/RowAdapter.swift index f987db864..ad9d257d1 100644 --- a/GRDB/Core/RowAdapter.swift +++ b/GRDB/Core/RowAdapter.swift @@ -523,7 +523,7 @@ struct AdaptedRowImpl: RowImpl { mapping.columnName(atMappingIndex: index) } - func index(ofColumn name: String) -> Int? { + func index(forColumn name: String) -> Int? { mapping.layoutIndex(ofColumn: name) } diff --git a/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift b/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift index fcce8fd0f..4c789f505 100644 --- a/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift +++ b/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift @@ -618,7 +618,7 @@ private func prefetch(_ db: Database, associations: [SQLAssociation], in rows: [ // TODO: can we remove those grdb_ columns now that grouping has been done? } - let groupingIndexes = firstRow.indexes(ofColumns: pivotMappings.map(\.left)) + let groupingIndexes = firstRow.indexes(forColumns: pivotMappings.map(\.left)) for row in rows { let groupingKey = groupingIndexes.map { row.impl.databaseValue(atUncheckedIndex: $0) } let prefetchedRows = prefetchedRows[groupingKey, default: []] @@ -634,7 +634,7 @@ extension Array where Element == Row { guard let firstRow = first else { return [:] } - let indexes = firstRow.indexes(ofColumns: columns) + let indexes = firstRow.indexes(forColumns: columns) return Dictionary(grouping: self, by: { row in indexes.map { row.impl.databaseValue(atUncheckedIndex: $0) } }) @@ -643,9 +643,9 @@ extension Array where Element == Row { extension Row { /// - precondition: Columns all exist in the row. - fileprivate func indexes(ofColumns columns: [String]) -> [Int] { + fileprivate func indexes(forColumns columns: [String]) -> [Int] { columns.map { column -> Int in - guard let index = index(ofColumn: column) else { + guard let index = index(forColumn: column) else { fatalError("Column \(column) is not selected") } return index diff --git a/GRDB/Record/FetchableRecord+Decodable.swift b/GRDB/Record/FetchableRecord+Decodable.swift index 4cfa3569e..6fbb13a49 100644 --- a/GRDB/Record/FetchableRecord+Decodable.swift +++ b/GRDB/Record/FetchableRecord+Decodable.swift @@ -53,7 +53,7 @@ private struct _RowDecoder: Decoder { guard let key = codingPath.last else { fatalError("single value decoding from database row is not supported") } - guard let index = row.index(ofColumn: key.stringValue) else { + guard let index = row.index(forColumn: key.stringValue) else { // Don't use DecodingError.keyNotFound: // We need to specifically recognize missing columns in order to // provide correct feedback. @@ -117,7 +117,7 @@ private struct _RowDecoder: Decoder { let keyName = key.stringValue // Column? - if let index = row.index(ofColumn: keyName) { + if let index = row.index(forColumn: keyName) { // Prefer DatabaseValueConvertible decoding over Decodable. // This allows decoding Date from String, or DatabaseValue from NULL. if type == Date.self { @@ -147,7 +147,7 @@ private struct _RowDecoder: Decoder { let keyName = key.stringValue // Column? - if let index = row.index(ofColumn: keyName) { + if let index = row.index(forColumn: keyName) { // Prefer DatabaseValueConvertible decoding over Decodable. // This allows decoding Date from String, or DatabaseValue from NULL. if type == Date.self {