@@ -452,7 +452,7 @@ extension Row {
452452 /// ```
453453 @inlinable
454454 public subscript< Value: DatabaseValueConvertible > ( _ columnName: String ) -> Value {
455- try ! decode ( Value . self, forKey : columnName)
455+ try ! decode ( Value . self, forColumn : columnName)
456456 }
457457
458458 /// Returns the value at given column, converted to the requested type.
@@ -489,7 +489,7 @@ extension Row {
489489 /// ```
490490 @inlinable
491491 public subscript< Value: DatabaseValueConvertible & StatementColumnConvertible > ( _ columnName: String ) -> Value {
492- try ! decode ( Value . self, forKey : columnName)
492+ try ! decode ( Value . self, forColumn : columnName)
493493 }
494494
495495 /// Returns `Int64`, `Double`, `String`, `Data` or nil, depending on the
@@ -533,7 +533,7 @@ extension Row {
533533 /// ```
534534 @inlinable
535535 public subscript< Value: DatabaseValueConvertible > ( _ column: some ColumnExpression ) -> Value {
536- try ! decode ( Value . self, forKey : column. name )
536+ try ! decode ( Value . self, forColumn : column)
537537 }
538538
539539 /// Returns the value at given column, converted to the requested type.
@@ -573,7 +573,7 @@ extension Row {
573573 -> Value
574574 where Value: DatabaseValueConvertible & StatementColumnConvertible
575575 {
576- try ! decode ( Value . self, forKey : column. name )
576+ try ! decode ( Value . self, forColumn : column)
577577 }
578578
579579 /// Calls the given closure with the `Data` at given index.
@@ -1068,7 +1068,7 @@ extension Row {
10681068 /// If the SQLite value is NULL, or if the conversion fails, a
10691069 /// `RowDecodingError` is thrown.
10701070 @inlinable
1071- func decode< Value: DatabaseValueConvertible > (
1071+ public func decode< Value: DatabaseValueConvertible > (
10721072 _ type: Value . Type = Value . self,
10731073 atIndex index: Int )
10741074 throws -> Value
@@ -1086,9 +1086,9 @@ extension Row {
10861086 /// or if the SQLite value can not be converted to `Value`, a
10871087 /// `RowDecodingError` is thrown.
10881088 @inlinable
1089- func decode< Value: DatabaseValueConvertible > (
1089+ public func decode< Value: DatabaseValueConvertible > (
10901090 _ type: Value . Type = Value . self,
1091- forKey columnName: String )
1091+ forColumn columnName: String )
10921092 throws -> Value
10931093 {
10941094 guard let index = index ( forColumn: columnName) else {
@@ -1100,6 +1100,23 @@ extension Row {
11001100 }
11011101 return try Value . decode ( fromRow: self , atUncheckedIndex: index)
11021102 }
1103+
1104+ /// Returns the value at given column, converted to the requested type.
1105+ ///
1106+ /// Column name lookup is case-insensitive. When several columns exist with
1107+ /// the same name, the leftmost column is considered.
1108+ ///
1109+ /// If the row does not contain the column, or if the SQLite value is NULL,
1110+ /// or if the SQLite value can not be converted to `Value`, a
1111+ /// `RowDecodingError` is thrown.
1112+ @inlinable
1113+ public func decode< Value: DatabaseValueConvertible > (
1114+ _ type: Value . Type = Value . self,
1115+ forColumn column: some ColumnExpression )
1116+ throws -> Value
1117+ {
1118+ try decode ( type, forColumn: column. name)
1119+ }
11031120}
11041121
11051122// MARK: - Throwing DatabaseValueConvertible & StatementColumnConvertible Decoding Methods
@@ -1118,7 +1135,7 @@ extension Row {
11181135 /// `RowDecodingError` is thrown.
11191136 @inline ( __always)
11201137 @inlinable
1121- func decode< Value: DatabaseValueConvertible & StatementColumnConvertible > (
1138+ public func decode< Value: DatabaseValueConvertible & StatementColumnConvertible > (
11221139 _ type: Value . Type = Value . self,
11231140 atIndex index: Int )
11241141 throws -> Value
@@ -1140,9 +1157,9 @@ extension Row {
11401157 /// or if the SQLite value can not be converted to `Value`, a
11411158 /// `RowDecodingError` is thrown.
11421159 @inlinable
1143- func decode< Value: DatabaseValueConvertible & StatementColumnConvertible > (
1160+ public func decode< Value: DatabaseValueConvertible & StatementColumnConvertible > (
11441161 _ type: Value . Type = Value . self,
1145- forKey columnName: String )
1162+ forColumn columnName: String )
11461163 throws -> Value
11471164 {
11481165 guard let index = index ( forColumn: columnName) else {
@@ -1155,6 +1172,27 @@ extension Row {
11551172 return try Value . fastDecode ( fromRow: self , atUncheckedIndex: index)
11561173 }
11571174
1175+ /// Returns the value at given column, converted to the requested type.
1176+ ///
1177+ /// This method exists as an optimization opportunity for types that adopt
1178+ /// ``StatementColumnConvertible``. It can trigger [SQLite built-in
1179+ /// conversions](https://www.sqlite.org/datatype3.html).
1180+ ///
1181+ /// Column name lookup is case-insensitive. When several columns exist with
1182+ /// the same name, the leftmost column is considered.
1183+ ///
1184+ /// If the row does not contain the column, or if the SQLite value is NULL,
1185+ /// or if the SQLite value can not be converted to `Value`, a
1186+ /// `RowDecodingError` is thrown.
1187+ @inlinable
1188+ public func decode< Value: DatabaseValueConvertible & StatementColumnConvertible > (
1189+ _ type: Value . Type = Value . self,
1190+ forColumn column: some ColumnExpression )
1191+ throws -> Value
1192+ {
1193+ try decode ( type, forColumn: column. name)
1194+ }
1195+
11581196 // Support for fast decoding in scoped rows
11591197 @usableFromInline
11601198 func fastDecode< Value: DatabaseValueConvertible & StatementColumnConvertible > (
@@ -1217,7 +1255,7 @@ extension Row {
12171255 /// null values.
12181256 ///
12191257 /// See ``splittingRowAdapters(columnCounts:)`` for a sample code.
1220- func decodeIfPresent< Record: FetchableRecord > (
1258+ public func decodeIfPresent< Record: FetchableRecord > (
12211259 _ type: Record . Type = Record . self,
12221260 forKey scope: String )
12231261 throws -> Record ?
@@ -1258,7 +1296,7 @@ extension Row {
12581296 /// null values.
12591297 ///
12601298 /// See ``splittingRowAdapters(columnCounts:)`` for a sample code.
1261- func decode< Record: FetchableRecord > (
1299+ public func decode< Record: FetchableRecord > (
12621300 _ type: Record . Type = Record . self,
12631301 forKey scope: String )
12641302 throws -> Record
@@ -1313,7 +1351,7 @@ extension Row {
13131351 /// let books: [Book] = row["books"]
13141352 /// print(books[0].title)
13151353 /// // Prints "Moby-Dick"
1316- func decode< Collection> (
1354+ public func decode< Collection> (
13171355 _ type: Collection . Type = Collection . self,
13181356 forKey key: String )
13191357 throws -> Collection
@@ -1364,7 +1402,7 @@ extension Row {
13641402 /// let books: Set<Book> = row["books"]
13651403 /// print(books.first!.title)
13661404 /// // Prints "Moby-Dick"
1367- func decode< Record: FetchableRecord & Hashable > (
1405+ public func decode< Record: FetchableRecord & Hashable > (
13681406 _ type: Set < Record > . Type = Set< Record> . self ,
13691407 forKey key: String )
13701408 throws -> Set < Record >
0 commit comments