@@ -9,18 +9,14 @@ public struct PostgresRowSequence: AsyncSequence, Sendable {
9
9
10
10
typealias BackingSequence = NIOThrowingAsyncSequenceProducer < DataRow , Error , AdaptiveRowBuffer , PSQLRowStream >
11
11
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 ]
20
15
21
- init ( _ backing: BackingSequence , rowStream : PSQLRowStream ) {
16
+ init ( _ backing: BackingSequence , lookupTable : [ String : Int ] , columns : [ RowDescription . Column ] ) {
22
17
self . backing = backing
23
- self . rowStream = rowStream
18
+ self . lookupTable = lookupTable
19
+ self . columns = columns
24
20
}
25
21
26
22
public func makeAsyncIterator( ) -> AsyncIterator {
@@ -30,10 +26,6 @@ public struct PostgresRowSequence: AsyncSequence, Sendable {
30
26
columns: self . columns
31
27
)
32
28
}
33
-
34
- func drain( ) {
35
- self . backing
36
- }
37
29
}
38
30
39
31
extension PostgresRowSequence {
@@ -68,15 +60,14 @@ extension PostgresRowSequence {
68
60
extension PostgresRowSequence. AsyncIterator : Sendable { }
69
61
70
62
extension 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)
78
69
}
79
- return metadata
70
+ return result
80
71
}
81
72
}
82
73
0 commit comments