Skip to content

Commit a117d11

Browse files
committed
revert unneeded changes
1 parent 6c85b3e commit a117d11

File tree

3 files changed

+26
-28
lines changed

3 files changed

+26
-28
lines changed

Sources/PostgresNIO/Connection/PostgresConnection.swift

+11-4
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,13 @@ extension PostgresConnection {
463463
self.channel.write(HandlerTask.extendedQuery(context), promise: nil)
464464

465465
do {
466-
let rowSequence = try await promise.futureResult.map({ $0.asyncSequence() }).get()
466+
let rowStream = try await promise.futureResult.get()
467+
let rowSequence = rowStream.asyncSequence()
467468
let result = try await consume(rowSequence)
468-
let metadata = try await rowSequence.drainAndCollectMetadata()
469+
try await rowStream.drain().get()
470+
guard let metadata = PostgresQueryMetadata(string: rowStream.commandTag) else {
471+
throw PSQLError.invalidCommandTag(rowStream.commandTag)
472+
}
469473
return (result, metadata)
470474
} catch var error as PSQLError {
471475
error.file = file
@@ -593,8 +597,11 @@ extension PostgresConnection {
593597
self.channel.write(HandlerTask.extendedQuery(context), promise: nil)
594598

595599
do {
596-
let rowSequence = try await promise.futureResult.map({ $0.asyncSequence() }).get()
597-
let metadata = try await rowSequence.drainAndCollectMetadata()
600+
let rowStream = try await promise.futureResult.get()
601+
try await rowStream.drain().get()
602+
guard let metadata = PostgresQueryMetadata(string: rowStream.commandTag) else {
603+
throw PSQLError.invalidCommandTag(rowStream.commandTag)
604+
}
598605
return metadata
599606
} catch var error as PSQLError {
600607
error.file = file

Sources/PostgresNIO/New/PSQLRowStream.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ final class PSQLRowStream: @unchecked Sendable {
4444
}
4545

4646
internal let rowDescription: [RowDescription.Column]
47-
internal let lookupTable: [String: Int]
47+
private let lookupTable: [String: Int]
4848
private var downstreamState: DownstreamState
4949

5050
init(
@@ -114,7 +114,7 @@ final class PSQLRowStream: @unchecked Sendable {
114114
self.downstreamState = .consumed(.failure(error))
115115
}
116116

117-
return PostgresRowSequence(producer.sequence, rowStream: self)
117+
return PostgresRowSequence(producer.sequence, lookupTable: self.lookupTable, columns: self.rowDescription)
118118
}
119119

120120
func demand() {

Sources/PostgresNIO/New/PostgresRowSequence.swift

+13-22
Original file line numberDiff line numberDiff line change
@@ -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

3931
extension PostgresRowSequence {
@@ -68,15 +60,14 @@ extension PostgresRowSequence {
6860
extension PostgresRowSequence.AsyncIterator: Sendable {}
6961

7062
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)
7869
}
79-
return metadata
70+
return result
8071
}
8172
}
8273

0 commit comments

Comments
 (0)