Skip to content

Commit 6709f03

Browse files
committed
small close fixes and asymetric stream fix
1 parent c686bd4 commit 6709f03

File tree

4 files changed

+39
-13
lines changed

4 files changed

+39
-13
lines changed

Sources/PostgreSQL/Connection/PostgreSQLConnection.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,14 @@ public final class AsymmetricQueueStream<I, O>: Stream, ConnectionContext {
144144

145145
do {
146146
if try context.onInput(input) {
147-
context.promise.complete()
148147
currentInput = nil
148+
context.promise.complete()
149149
} else {
150150
upstream!.request(count: 1)
151151
}
152152
} catch {
153-
context.promise.fail(error)
154153
currentInput = nil
154+
context.promise.fail(error)
155155
}
156156
}
157157
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import Bits
2+
3+
/// Identifies the message as a Close command.
4+
struct PostgreSQLClose: Decodable {
5+
/// 'S' to close a prepared statement; or 'P' to close a portal.
6+
var type: PostgreSQLCloseType
7+
8+
/// See `Decodable.init(from:)`
9+
init(from decoder: Decoder) throws {
10+
let single = try decoder.singleValueContainer()
11+
let string = try single.decode(String.self)
12+
/// This message format is overloaded with `C` byte identifier.
13+
/// We need to do some checking to see what type it actually is.
14+
switch string.first {
15+
case .some(let c):
16+
switch c {
17+
case "S": type = .statement(name: String(string[string.index(after: string.startIndex)...]))
18+
case "P": type = .portal(name: String(string[string.index(after: string.startIndex)...]))
19+
default: type = .command(string)
20+
}
21+
default: type = .command(string)
22+
}
23+
}
24+
}
25+
26+
27+
enum PostgreSQLCloseType {
28+
/// The name of the prepared statement or portal to close (an empty string selects the unnamed prepared statement or portal).
29+
case statement(name: String)
30+
/// The name of the prepared statement or portal to close (an empty string selects the unnamed prepared statement or portal).
31+
case portal(name: String)
32+
/// The command tag. This is usually a single word that identifies which SQL command was completed.
33+
case command(String)
34+
}
35+

Sources/PostgreSQL/Message/PostgreSQLCloseCommand.swift

-10
This file was deleted.

Sources/PostgreSQL/Message/PostgreSQLMessage.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ enum PostgreSQLMessage {
1414
case query(PostgreSQLQuery)
1515
case rowDescription(PostgreSQLRowDescription)
1616
case dataRow(PostgreSQLDataRow)
17-
case close(PostgreSQLCloseCommand)
17+
/// Identifies the message as a command-completed response.
18+
case close(PostgreSQLClose)
1819
case parse(PostgreSQLParseRequest)
1920
/// Identifies the message as a parameter description.
2021
case parameterDescription(PostgreSQLParameterDescription)

0 commit comments

Comments
 (0)