@@ -13,7 +13,7 @@ extension SQLQueryFetcher {
1313 /// - type: The type of the desired value.
1414 /// - Returns: A future containing the decoded value, if any.
1515 @inlinable
16- public func first< D: Decodable > ( decodingColumn column: String , as type: D . Type ) -> EventLoopFuture < D ? > {
16+ public func first< D: Decodable & _SQLKitSendableMetatype > ( decodingColumn column: String , as type: D . Type ) -> EventLoopFuture < D ? > {
1717 self . first ( ) . flatMapThrowing { try $0? . decode ( column: column, as: D . self) }
1818 }
1919
@@ -22,7 +22,7 @@ extension SQLQueryFetcher {
2222 /// - Parameter type: The type of the desired value.
2323 /// - Returns: A future containing the decoded value, if any.
2424 @inlinable
25- public func first< D: Decodable > ( decoding type: D . Type ) -> EventLoopFuture < D ? > {
25+ public func first< D: Decodable & _SQLKitSendableMetatype > ( decoding type: D . Type ) -> EventLoopFuture < D ? > {
2626 self . first ( decoding: D . self, with: . init( ) )
2727 }
2828
@@ -36,7 +36,7 @@ extension SQLQueryFetcher {
3636 /// - userInfo: See ``SQLRowDecoder/userInfo``.
3737 /// - Returns: A future containing the decoded value, if any.
3838 @inlinable
39- public func first< D: Decodable > (
39+ public func first< D: Decodable & _SQLKitSendableMetatype > (
4040 decoding type: D . Type ,
4141 prefix: String ? = nil ,
4242 keyDecodingStrategy: SQLRowDecoder . KeyDecodingStrategy = . useDefaultKeys,
@@ -52,7 +52,7 @@ extension SQLQueryFetcher {
5252 /// - decoder: A configured ``SQLRowDecoder`` to use.
5353 /// - Returns: A future containing the decoded value, if any.
5454 @inlinable
55- public func first< D: Decodable > ( decoding type: D . Type , with decoder: SQLRowDecoder ) -> EventLoopFuture < D ? > {
55+ public func first< D: Decodable & _SQLKitSendableMetatype > ( decoding type: D . Type , with decoder: SQLRowDecoder ) -> EventLoopFuture < D ? > {
5656 self . first ( ) . flatMapThrowing { try $0? . decode ( model: D . self, with: decoder) }
5757 }
5858
@@ -65,13 +65,8 @@ extension SQLQueryFetcher {
6565 @inlinable
6666 public func first( ) -> EventLoopFuture < ( any SQLRow ) ? > {
6767 ( self as? any SQLPartialResultBuilder ) ? . limit ( 1 )
68- #if swift(>=5.10)
6968 nonisolated ( unsafe) var rows = [ any SQLRow ] ( )
7069 return self . run { if rows. isEmpty { rows. append ( $0) } } . map { rows. first }
71- #else
72- let rows = RowsBox ( )
73- return self . run { if rows. all. isEmpty { rows. all. append ( $0) } } . map { rows. all. first }
74- #endif
7570 }
7671}
7772
@@ -137,15 +132,9 @@ extension SQLQueryFetcher {
137132 @inlinable
138133 public func first( ) async throws -> ( any SQLRow ) ? {
139134 ( self as? any SQLPartialResultBuilder ) ? . limit ( 1 )
140- #if swift(>=5.10)
141135 nonisolated ( unsafe) var rows = [ any SQLRow ] ( )
142136 try await self . run { if rows. isEmpty { rows. append ( $0) } }
143137 return rows. first
144- #else
145- let rows = RowsBox ( )
146- try await self . run { if rows. all. isEmpty { rows. all. append ( $0) } }
147- return rows. all. first
148- #endif
149138 }
150139}
151140
@@ -159,7 +148,7 @@ extension SQLQueryFetcher {
159148 /// - type: The type of the desired values.
160149 /// - Returns: A future containing the decoded values, if any.
161150 @inlinable
162- public func all< D: Decodable > ( decodingColumn column: String , as type: D . Type ) -> EventLoopFuture < [ D ] > {
151+ public func all< D: Decodable & _SQLKitSendableMetatype > ( decodingColumn column: String , as type: D . Type ) -> EventLoopFuture < [ D ] > {
163152 self . all ( ) . flatMapThrowing { try $0. map { try $0. decode ( column: column, as: D . self) } }
164153 }
165154
@@ -168,7 +157,7 @@ extension SQLQueryFetcher {
168157 /// - Parameter type: The type of the desired values.
169158 /// - Returns: A future containing the decoded values, if any.
170159 @inlinable
171- public func all< D: Decodable > ( decoding type: D . Type ) -> EventLoopFuture < [ D ] > {
160+ public func all< D: Decodable & _SQLKitSendableMetatype > ( decoding type: D . Type ) -> EventLoopFuture < [ D ] > {
172161 self . all ( decoding: D . self, with: . init( ) )
173162 }
174163
@@ -182,7 +171,7 @@ extension SQLQueryFetcher {
182171 /// - userInfo: See ``SQLRowDecoder/userInfo``.
183172 /// - Returns: A future containing the decoded values, if any.
184173 @inlinable
185- public func all< D: Decodable > (
174+ public func all< D: Decodable & _SQLKitSendableMetatype > (
186175 decoding type: D . Type ,
187176 prefix: String ? = nil ,
188177 keyDecodingStrategy: SQLRowDecoder . KeyDecodingStrategy = . useDefaultKeys,
@@ -198,7 +187,7 @@ extension SQLQueryFetcher {
198187 /// - decoder: A configured ``SQLRowDecoder`` to use.
199188 /// - Returns: A future containing the decoded values, if any.
200189 @inlinable
201- public func all< D: Decodable > ( decoding type: D . Type , with decoder: SQLRowDecoder ) -> EventLoopFuture < [ D ] > {
190+ public func all< D: Decodable & _SQLKitSendableMetatype > ( decoding type: D . Type , with decoder: SQLRowDecoder ) -> EventLoopFuture < [ D ] > {
202191 self . all ( ) . flatMapThrowing { try $0. map { try $0. decode ( model: D . self, with: decoder) } }
203192 }
204193
@@ -207,13 +196,8 @@ extension SQLQueryFetcher {
207196 /// - Returns: A future containing the output rows, if any.
208197 @inlinable
209198 public func all( ) -> EventLoopFuture < [ any SQLRow ] > {
210- #if swift(>=5.10)
211199 nonisolated ( unsafe) var rows = [ any SQLRow ] ( )
212200 return self . run { row in rows. append ( row) } . map { rows }
213- #else
214- let rows = RowsBox ( )
215- return self . run { row in rows. all. append ( row) } . map { rows. all }
216- #endif
217201 }
218202}
219203
@@ -275,15 +259,9 @@ extension SQLQueryFetcher {
275259 /// - Returns: The output rows, if any.
276260 @inlinable
277261 public func all( ) async throws -> [ any SQLRow ] {
278- #if swift(>=5.10)
279262 nonisolated ( unsafe) var rows = [ any SQLRow ] ( )
280263 try await self . run { rows. append ( $0) }
281264 return rows
282- #else
283- let rows = RowsBox ( )
284- try await self . run { rows. all. append ( $0) }
285- return rows. all
286- #endif
287265 }
288266}
289267
@@ -299,7 +277,7 @@ extension SQLQueryFetcher {
299277 /// - Returns: A completion future.
300278 @preconcurrency
301279 @inlinable
302- public func run< D: Decodable > ( decoding type: D . Type , _ handler: @escaping @Sendable ( Result < D , any Error > ) -> ( ) ) -> EventLoopFuture < Void > {
280+ public func run< D: Decodable & _SQLKitSendableMetatype > ( decoding type: D . Type , _ handler: @escaping @Sendable ( Result < D , any Error > ) -> ( ) ) -> EventLoopFuture < Void > {
303281 self . run ( decoding: D . self, with: . init( ) , handler)
304282 }
305283
@@ -315,7 +293,7 @@ extension SQLQueryFetcher {
315293 /// - Returns: A completion future.
316294 @preconcurrency
317295 @inlinable
318- public func run< D: Decodable > (
296+ public func run< D: Decodable & _SQLKitSendableMetatype > (
319297 decoding type: D . Type ,
320298 prefix: String ? = nil ,
321299 keyDecodingStrategy: SQLRowDecoder . KeyDecodingStrategy = . useDefaultKeys,
@@ -335,7 +313,7 @@ extension SQLQueryFetcher {
335313 /// - Returns: A completion future.
336314 @preconcurrency
337315 @inlinable
338- public func run< D: Decodable > (
316+ public func run< D: Decodable & _SQLKitSendableMetatype > (
339317 decoding type: D . Type ,
340318 with decoder: SQLRowDecoder ,
341319 _ handler: @escaping @Sendable ( Result < D , any Error > ) -> ( )
@@ -365,7 +343,7 @@ extension SQLQueryFetcher {
365343 /// - type: The type of the desired values.
366344 /// - handler: A closure which receives the result of each decoding operation, row by row.
367345 @inlinable
368- public func run< D: Decodable > ( decoding type: D . Type , _ handler: @escaping @Sendable ( Result < D , any Error > ) -> ( ) ) async throws {
346+ public func run< D: Decodable & _SQLKitSendableMetatype > ( decoding type: D . Type , _ handler: @escaping @Sendable ( Result < D , any Error > ) -> ( ) ) async throws {
369347 try await self . run ( decoding: D . self, with: . init( ) , handler)
370348 }
371349
@@ -380,7 +358,7 @@ extension SQLQueryFetcher {
380358 /// - handler: A closure which receives the result of each decoding operation, row by row.
381359 @inlinable
382360 @preconcurrency
383- public func run< D: Decodable > (
361+ public func run< D: Decodable & _SQLKitSendableMetatype > (
384362 decoding type: D . Type ,
385363 prefix: String ? = nil ,
386364 keyDecodingStrategy: SQLRowDecoder . KeyDecodingStrategy = . useDefaultKeys,
@@ -399,7 +377,7 @@ extension SQLQueryFetcher {
399377 /// - handler: A closure which receives the result of each decoding operation, row by row.
400378 @inlinable
401379 @preconcurrency
402- public func run< D: Decodable > (
380+ public func run< D: Decodable & _SQLKitSendableMetatype > (
403381 decoding type: D . Type ,
404382 with decoder: SQLRowDecoder ,
405383 _ handler: @escaping @Sendable ( Result < D , any Error > ) -> ( )
@@ -419,18 +397,8 @@ extension SQLQueryFetcher {
419397
420398// MARK: - Utility
421399
422- #if swift(<5.10)
423-
424- /// A simple helper type for working with a mutable value capture across concurrency domains.
425- ///
426- /// Only used before Swift 5.10.
427- @usableFromInline
428- final class RowsBox : @unchecked Sendable {
429- @usableFromInline
430- var all : [ any SQLRow ] = [ ]
431-
432- @usableFromInline
433- init ( ) { }
434- }
435-
400+ #if compiler(>=6.2)
401+ public typealias _SQLKitSendableMetatype = SendableMetatype
402+ #else
403+ public typealias _SQLKitSendableMetatype = Any
436404#endif
0 commit comments