@@ -9,18 +9,14 @@ public struct PostgresRowSequence: AsyncSequence, Sendable {
99
1010 typealias BackingSequence = NIOThrowingAsyncSequenceProducer < DataRow , Error , AdaptiveRowBuffer , PSQLRowStream >
1111
12- private let backing : BackingSequence
13- private let rowStream : PSQLRowStream
14- var lookupTable : [ String : Int ] {
15- self . rowStream. lookupTable
16- }
17- var columns : [ RowDescription . Column ] {
18- self . rowStream. rowDescription
19- }
12+ let backing : BackingSequence
13+ let lookupTable : [ String : Int ]
14+ let columns : [ RowDescription . Column ]
2015
21- init ( _ backing: BackingSequence , rowStream : PSQLRowStream ) {
16+ init ( _ backing: BackingSequence , lookupTable : [ String : Int ] , columns : [ RowDescription . Column ] ) {
2217 self . backing = backing
23- self . rowStream = rowStream
18+ self . lookupTable = lookupTable
19+ self . columns = columns
2420 }
2521
2622 public func makeAsyncIterator( ) -> AsyncIterator {
@@ -30,10 +26,6 @@ public struct PostgresRowSequence: AsyncSequence, Sendable {
3026 columns: self . columns
3127 )
3228 }
33-
34- func drain( ) {
35- self . backing
36- }
3729}
3830
3931extension PostgresRowSequence {
@@ -68,15 +60,14 @@ extension PostgresRowSequence {
6860extension PostgresRowSequence. AsyncIterator : Sendable { }
6961
7062extension PostgresRowSequence {
71- /// Collects the query metadata.
72- /// Should be called after the sequence is consumed, otherwise throws `PSQLError`.
73- /// - Returns: The metadata.
74- func drainAndCollectMetadata( ) async throws -> PostgresQueryMetadata {
75- try await self . rowStream. drain ( ) . get ( )
76- guard let metadata = PostgresQueryMetadata ( string: self . rowStream. commandTag) else {
77- throw PSQLError . invalidCommandTag ( self . rowStream. commandTag)
63+ /// Collects all rows into an array.
64+ /// - Returns: The rows.
65+ public func collect( ) async throws -> [ PostgresRow ] {
66+ var result = [ PostgresRow] ( )
67+ for try await row in self {
68+ result. append ( row)
7869 }
79- return metadata
70+ return result
8071 }
8172}
8273
0 commit comments