mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-25 04:07:47 +00:00
Rename index(ofColumn:) to index(forColumn:)
This commit is contained in:
1 parent
0dc18cdaab
commit
27ffb2a418
5 files changed
+24
-24
No files matched your search
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+15
-15
@@ -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<Value: DatabaseValueConvertible>(_ 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<Value: DatabaseValueConvertible & StatementColumnConvertible>(_ 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<Value: DatabaseValueConvertible>(_ 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<Value: DatabaseValueConvertible & StatementColumnConvertible>(_ 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..<count where columnName(atUncheckedIndex: index).lowercased() == name {
|
||||
return index
|
||||
@@ -1839,7 +1839,7 @@ private struct EmptyRowImpl: RowImpl {
|
||||
fatalError("row index out of range")
|
||||
}
|
||||
|
||||
func index(ofColumn name: String) -> Int? { nil }
|
||||
func index(forColumn name: String) -> Int? { nil }
|
||||
|
||||
func copiedRow(_ row: Row) -> Row { row }
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -53,7 +53,7 @@ private struct _RowDecoder<R: FetchableRecord>: 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<R: FetchableRecord>: 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<R: FetchableRecord>: 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 {
|
||||
|
||||
Reference in new issue
Block a user