forked from vapor/postgres-nio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostgresMessage+ReadyForQuery.swift
26 lines (23 loc) · 1.18 KB
/
PostgresMessage+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
import NIO
extension PostgresMessage {
/// Identifies the message type. ReadyForQuery is sent whenever the backend is ready for a new query cycle.
public struct ReadyForQuery: CustomStringConvertible {
/// Parses an instance of this message type from a byte buffer.
public static func parse(from buffer: inout ByteBuffer) throws -> ReadyForQuery {
guard let status = buffer.readInteger(as: UInt8.self) else {
throw PostgresError.protocol("Could not read transaction status from ready for query message")
}
return .init(transactionStatus: status)
}
/// 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).
public var transactionStatus: UInt8
/// See `CustomStringConvertible`.
public var description: String {
let char = String(bytes: [transactionStatus], encoding: .ascii) ?? "n/a"
return "transactionStatus: \(char)"
}
}
}