forked from vapor/postgres-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostgreSQLMessage+ReadyForQuery.swift
33 lines (28 loc) · 1.23 KB
/
PostgreSQLMessage+ReadyForQuery.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
extension PostgreSQLMessage {
/// Identifies the message type. ReadyForQuery is sent whenever the backend is ready for a new query cycle.
struct ReadyForQuery {
/// Current backend transaction status indicator.
/// Possible values are 'I' if idle (not in a transaction block);
/// 'T' if in a transaction block; or 'E' if in a failed transaction block
/// (queries will be rejected until block is ended).
var transactionStatus: UInt8
}
}
// MARK: String
extension PostgreSQLMessage.ReadyForQuery: CustomStringConvertible {
/// See `CustomStringConvertible`.
var description: String {
let char = String(bytes: [transactionStatus], encoding: .ascii) ?? "n/a"
return "transactionStatus: \(char)"
}
}
// MARK: Parse
extension PostgreSQLMessage.ReadyForQuery {
/// Parses an instance of this message type from a byte buffer.
static func parse(from buffer: inout ByteBuffer) throws -> PostgreSQLMessage.ReadyForQuery {
guard let status = buffer.readInteger(as: UInt8.self) else {
throw PostgreSQLError.protocol(reason: "Could not read transaction status from ready for query message.")
}
return .init(transactionStatus: status)
}
}