22
33extension  PostgresRow  { 
44
5+     // --- snip TODO: Remove once bug is fixed, that disallows tuples of one
6+     @inlinable  
57    public  func  decode< Column:  PostgresDecodable > ( 
68        _:  Column . Type , 
79        file:  String  =  #file, 
@@ -10,6 +12,7 @@ extension PostgresRow {
1012        try self . decode ( Column . self,  context:  . default,  file:  file,  line:  line) 
1113    } 
1214
15+     @inlinable  
1316    public  func  decode< Column:  PostgresDecodable > ( 
1417        _:  Column . Type , 
1518        context:  PostgresDecodingContext < some  PostgresJSONDecoder > , 
@@ -42,18 +45,64 @@ extension PostgresRow {
4245            ) 
4346        } 
4447    } 
48+     // --- snap TODO: Remove once bug is fixed, that disallows tuples of one
4549
50+ //    @inlinable // <--- commenting this in, crashes the compiler
4651    public  func  decode< each  Column :  PostgresDecodable > ( 
4752        _ columnType:  ( repeat  each  Column ) . Type, 
4853        context:  PostgresDecodingContext < some  PostgresJSONDecoder > , 
4954        file:  String  =  #file, 
5055        line:  Int  =  #line
5156    )  throws  ->  ( repeat  each  Column )  { 
57+         var  columnIndex  =  0 
58+         var  cellIterator  =  self . data. makeIterator ( ) 
59+         var  columnIterator  =  self . columns. makeIterator ( ) 
60+ 
61+         return  ( 
62+             repeat  try Self . decodeNextColumn ( 
63+                 ( each  Column) . self, 
64+                 cellIterator:  & cellIterator, 
65+                 columnIterator:  & columnIterator, 
66+                 columnIndex:  & columnIndex, 
67+                 context:  context, 
68+                 file:  file, 
69+                 line:  line
70+             ) 
71+         ) 
72+     } 
5273
53-         var  iterator  =  self . makeIterator ( ) 
54-         return  ( repeat  try . next ( ) !. decode ( ( each  Column) . self,  context:  context) ) 
74+     @inlinable  
75+     static  func  decodeNextColumn< Column:  PostgresDecodable > ( 
76+         _ columnType:  Column . Type , 
77+         cellIterator:  inout  IndexingIterator < DataRow > , 
78+         columnIterator:  inout  IndexingIterator < [ RowDescription . Column ] > , 
79+         columnIndex:  inout  Int , 
80+         context:  PostgresDecodingContext < some  PostgresJSONDecoder > , 
81+         file:  String , 
82+         line:  Int 
83+     )  throws  ->  Column  { 
84+         defer  {  columnIndex +=  1  } 
85+ 
86+         let  column  =  columnIterator. next ( ) . unsafelyUnwrapped
87+         var  cellData  =  cellIterator. next ( ) . unsafelyUnwrapped
88+         do  { 
89+             return  try Column . _decodeRaw ( from:  & cellData,  type:  column. dataType,  format:  column. format,  context:  context) 
90+         }  catch  let  codePostgresDecodingError . Code  { 
91+             throw  PostgresDecodingError ( 
92+                 code:  code, 
93+                 columnName:  column. name, 
94+                 columnIndex:  columnIndex, 
95+                 targetType:  Column . self, 
96+                 postgresType:  column. dataType, 
97+                 postgresFormat:  column. format, 
98+                 postgresData:  cellData, 
99+                 file:  file, 
100+                 line:  line
101+             ) 
102+         } 
55103    } 
56104
105+ //    @inlinable // <--- commenting this in, crashes the compiler
57106    public  func  decode< each  Column :  PostgresDecodable > ( 
58107        _ columnType:  ( repeat  each  Column ) . Type, 
59108        file:  String  =  #file, 
@@ -62,48 +111,47 @@ extension PostgresRow {
62111        try self . decode ( columnType,  context:  . default,  file:  file,  line:  line) 
63112    } 
64113} 
65- //
66- //extension AsyncSequence where Element == PostgresRow {
67- //
68- //    public func decode<Column: PostgresDecodable>(
69- //        _: Column.Type,
70- //        context: PostgresDecodingContext<some PostgresJSONDecoder>,
71- //        file: String = #file,
72- //        line: Int = #line
73- //    ) -> AsyncThrowingMapSequence<Self, (Column)> {
74- //        self.map { row in
75- //            try row.decodeSingle(Column.self, context: context, file: file, line: line)
76- //        }
77- //    }
78- //
79- //    public func decode<Column: PostgresDecodable>(
80- //        _: Column.Type,
81- //        file: String = #file,
82- //        line: Int = #line
83- //    ) -> AsyncThrowingMapSequence<Self, (Column)> {
84- //        self.decode(Column.self, context: .default, file: file, line: line)
85- //    }
86- //
87- //    public func decode<each Column: PostgresDecodable>(
88- //        _ columnType: (repeat each Column).Type,
89- //        context: PostgresDecodingContext<some PostgresJSONDecoder>,
90- //        file: String = #file,
91- //        line: Int = #line
92- //    ) throws -> AsyncThrowingMapSequence<Self, (repeat each Column)> {
93- //        self.map { row in
94- //            try row.decode(columnType, context: context, file: file, line: line)
95- //        }
96- //    }
97- //
98- //    public func decode<each Column: PostgresDecodable>(
99- //        _ columnType: (repeat each Column).Type,
100- //        file: String = #file,
101- //        line: Int = #line
102- //    ) throws -> AsyncThrowingMapSequence<Self, (repeat each Column)> {
103- //        try self.decode(columnType, context: .default, file: file, line: line)
104- //    }
105- //
106- //
107- //}
114+ 
115+ #if false // commented out since, the AsyncSequence map currently crashes the compiler 
116+ extension  AsyncSequence  where  Element ==  PostgresRow  { 
117+     public  func  decode< Column:  PostgresDecodable > ( 
118+         _:  Column . Type , 
119+         context:  PostgresDecodingContext < some  PostgresJSONDecoder > , 
120+         file:  String  =  #file, 
121+         line:  Int  =  #line
122+     )  ->  AsyncThrowingMapSequence < Self ,  ( Column ) >  { 
123+         self . map  {  row in 
124+             try . decode ( Column . self,  context:  context,  file:  file,  line:  line) 
125+         } 
126+     } 
127+ 
128+     public  func  decode< Column:  PostgresDecodable > ( 
129+         _:  Column . Type , 
130+         file:  String  =  #file, 
131+         line:  Int  =  #line
132+     )  ->  AsyncThrowingMapSequence < Self ,  ( Column ) >  { 
133+         self . decode ( Column . self,  context:  . default,  file:  file,  line:  line) 
134+     } 
135+ 
136+     public  func  decode< each  Column :  PostgresDecodable > ( 
137+         _ columnType:  ( repeat  each  Column ) . Type, 
138+         context:  PostgresDecodingContext < some  PostgresJSONDecoder > , 
139+         file:  String  =  #file, 
140+         line:  Int  =  #line
141+     )  throws  ->  AsyncThrowingMapSequence < Self ,  ( repeat  each  Column ) >  { 
142+         self . map  {  row in 
143+             try . decode ( columnType,  context:  context,  file:  file,  line:  line) 
144+         } 
145+     } 
146+ 
147+     public  func  decode< each  Column :  PostgresDecodable > ( 
148+         _ columnType:  ( repeat  each  Column ) . Type, 
149+         file:  String  =  #file, 
150+         line:  Int  =  #line
151+     )  throws  ->  AsyncThrowingMapSequence < Self ,  ( repeat  each  Column ) >  { 
152+         try self . decode ( columnType,  context:  . default,  file:  file,  line:  line) 
153+     } 
154+ } 
155+ #endif 
108156
109157#endif 
0 commit comments