@@ -20,20 +20,18 @@ public struct StatementDecoder {
2020
2121private final class _StatementDecoder {
2222 let statement : PreparedStatement
23- let columns : [ String : Int32 ]
2423 let userInfo : [ CodingUserInfoKey : Any ]
2524 private( set) var codingPath : [ any CodingKey ] = [ ]
2625
2726 init ( statement: PreparedStatement , userInfo: [ CodingUserInfoKey : Any ] ) {
2827 self . statement = statement
2928 self . userInfo = userInfo
30- self . columns = statement. columnIndexByName
3129 self . codingPath. reserveCapacity ( 3 )
3230 }
3331
3432 @inline ( __always)
3533 func null< K> ( for key: K ) -> Bool where K: CodingKey {
36- columns [ key . stringValue ] . map { statement. columnNull ( at : $0 ) } ?? true
34+ statement. column ( for : key . stringValue ) ? . isNull ?? true
3735 }
3836
3937 @inline ( __always)
@@ -44,17 +42,20 @@ private final class _StatementDecoder {
4442 @inline ( __always)
4543 func string< K> ( forKey key: K , single: Bool = false ) throws -> String where K: CodingKey {
4644 let index = try columnIndex ( forKey: key, single: single)
47- guard let value = statement. columnString ( at: index) else {
45+ guard let value = statement. column ( at: index) . string else {
4846 throw DecodingError . valueNotFound ( String . self, context ( key, single, " " ) )
4947 }
5048 return value
5149 }
5250
5351 @inline ( __always)
54- func floating< T, K> ( _ type: T . Type , forKey key: K , single: Bool = false ) throws -> T
55- where T: BinaryFloatingPoint , K: CodingKey {
52+ func floating< T, K> (
53+ _ type: T . Type ,
54+ forKey key: K ,
55+ single: Bool = false
56+ ) throws -> T where T: BinaryFloatingPoint , K: CodingKey {
5657 let index = try columnIndex ( forKey: key, single: single)
57- let value = statement. columnDouble ( at: index)
58+ let value = statement. column ( at: index) . double
5859 guard let number = type. init ( exactly: value) else {
5960 throw DecodingError . dataCorrupted ( context ( key, single, numberNotFit ( type, value: " \( value) " ) ) )
6061 }
@@ -64,7 +65,7 @@ private final class _StatementDecoder {
6465 @inline ( __always)
6566 func integer< T, K> ( _ type: T . Type , forKey key: K , single: Bool = false ) throws -> T where T: Numeric , K: CodingKey {
6667 let index = try columnIndex ( forKey: key, single: single)
67- let value = statement. columnInt64 ( at: index)
68+ let value = statement. column ( at: index) . int64
6869 guard let number = type. init ( exactly: value) else {
6970 throw DecodingError . dataCorrupted ( context ( key, single, numberNotFit ( type, value: " \( value) " ) ) )
7071 }
@@ -79,7 +80,7 @@ private final class _StatementDecoder {
7980 ) throws -> T where T: Decodable , K: CodingKey {
8081 if type == Data . self {
8182 let index = try columnIndex ( forKey: key, single: single)
82- guard let data = statement. columnBlob ( at: index) else {
83+ guard let data = statement. column ( at: index) . blob else {
8384 throw DecodingError . valueNotFound ( Data . self, context ( key, single, " " ) )
8485 }
8586 // swift-format-ignore: NeverForceUnwrap
@@ -96,7 +97,7 @@ private final class _StatementDecoder {
9697 }
9798
9899 private func columnIndex< K> ( forKey key: K , single: Bool ) throws -> Int32 where K: CodingKey {
99- guard let index = columns [ key. stringValue] else {
100+ guard let index = statement . columnIndexByName [ key. stringValue] else {
100101 throw DecodingError . keyNotFound ( key, context ( key, single, " Column index not found for key: \( key) " ) )
101102 }
102103 return index
@@ -169,9 +170,9 @@ extension _StatementDecoder {
169170 struct KeyedContainer < Key: CodingKey > : KeyedDecodingContainerProtocol {
170171 let decoder : _StatementDecoder
171172 var codingPath : [ any CodingKey ] { decoder. codingPath }
172- var allKeys : [ Key ] { decoder. columns . keys. compactMap { Key ( stringValue: $0) } }
173+ var allKeys : [ Key ] { decoder. statement . columnIndexByName . keys. compactMap { Key ( stringValue: $0) } }
173174
174- func contains( _ key: Key ) -> Bool { decoder. columns . keys. contains ( key. stringValue) }
175+ func contains( _ key: Key ) -> Bool { decoder. statement . columnIndexByName . keys. contains ( key. stringValue) }
175176 func decodeNil( forKey key: Key ) throws -> Bool { decoder. null ( for: key) }
176177 func decode( _ type: Bool . Type , forKey key: Key ) throws -> Bool { try decoder. bool ( forKey: key) }
177178 func decode( _ type: String . Type , forKey key: Key ) throws -> String { try decoder. string ( forKey: key) }
0 commit comments