Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename PSQLBackendMessage to PostgresBackendMessage #238

Merged
merged 2 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/PostgresNIO/Connection/PostgresConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ extension PostgresConnection {
}

extension PostgresConnection: PSQLChannelHandlerNotificationDelegate {
func notificationReceived(_ notification: PSQLBackendMessage.NotificationResponse) {
func notificationReceived(_ notification: PostgresBackendMessage.NotificationResponse) {
self.underlying.eventLoop.assertInEventLoop()

guard let listeners = self.notificationListeners[notification.channel] else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct AuthenticationStateMachine {
return .sendStartupMessage(self.authContext)
}

mutating func authenticationMessageReceived(_ message: PSQLBackendMessage.Authentication) -> Action {
mutating func authenticationMessageReceived(_ message: PostgresBackendMessage.Authentication) -> Action {
switch self.state {
case .startupMessageSent:
switch message {
Expand Down Expand Up @@ -156,7 +156,7 @@ struct AuthenticationStateMachine {
}
}

mutating func errorReceived(_ message: PSQLBackendMessage.ErrorResponse) -> Action {
mutating func errorReceived(_ message: PostgresBackendMessage.ErrorResponse) -> Action {
return self.setAndFireError(.server(message))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct CloseStateMachine {
return .succeedClose(closeContext)
}

mutating func errorReceived(_ errorMessage: PSQLBackendMessage.ErrorResponse) -> Action {
mutating func errorReceived(_ errorMessage: PostgresBackendMessage.ErrorResponse) -> Action {
let error = PSQLError.server(errorMessage)
switch self.state {
case .initialized:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import NIOCore

struct ConnectionStateMachine {

typealias TransactionState = PSQLBackendMessage.TransactionState
typealias TransactionState = PostgresBackendMessage.TransactionState

struct ConnectionContext {
let processID: Int32
Expand Down Expand Up @@ -66,7 +66,7 @@ struct ConnectionStateMachine {
case sendSSLRequest
case establishSSLConnection
case provideAuthenticationContext
case forwardNotificationToListeners(PSQLBackendMessage.NotificationResponse)
case forwardNotificationToListeners(PostgresBackendMessage.NotificationResponse)
case fireEventReadyForQuery
case fireChannelInactive
/// Close the connection by sending a `Terminate` message and then closing the connection. This is for clean shutdowns.
Expand Down Expand Up @@ -298,7 +298,7 @@ struct ConnectionStateMachine {
}
}

mutating func authenticationMessageReceived(_ message: PSQLBackendMessage.Authentication) -> ConnectionAction {
mutating func authenticationMessageReceived(_ message: PostgresBackendMessage.Authentication) -> ConnectionAction {
guard case .authenticating(var authState) = self.state else {
return self.closeConnectionAndCleanup(.unexpectedBackendMessage(.authentication(message)))
}
Expand All @@ -310,7 +310,7 @@ struct ConnectionStateMachine {
}
}

mutating func backendKeyDataReceived(_ keyData: PSQLBackendMessage.BackendKeyData) -> ConnectionAction {
mutating func backendKeyDataReceived(_ keyData: PostgresBackendMessage.BackendKeyData) -> ConnectionAction {
guard case .authenticated(_, let parameters) = self.state else {
return self.closeConnectionAndCleanup(.unexpectedBackendMessage(.backendKeyData(keyData)))
}
Expand All @@ -323,7 +323,7 @@ struct ConnectionStateMachine {
return .wait
}

mutating func parameterStatusReceived(_ status: PSQLBackendMessage.ParameterStatus) -> ConnectionAction {
mutating func parameterStatusReceived(_ status: PostgresBackendMessage.ParameterStatus) -> ConnectionAction {
switch self.state {
case .sslRequestSent,
.sslNegotiated,
Expand Down Expand Up @@ -373,7 +373,7 @@ struct ConnectionStateMachine {
}
}

mutating func errorReceived(_ errorMessage: PSQLBackendMessage.ErrorResponse) -> ConnectionAction {
mutating func errorReceived(_ errorMessage: PostgresBackendMessage.ErrorResponse) -> ConnectionAction {
switch self.state {
case .sslRequestSent,
.sslNegotiated,
Expand Down Expand Up @@ -487,7 +487,7 @@ struct ConnectionStateMachine {
}
}

mutating func noticeReceived(_ notice: PSQLBackendMessage.NoticeResponse) -> ConnectionAction {
mutating func noticeReceived(_ notice: PostgresBackendMessage.NoticeResponse) -> ConnectionAction {
switch self.state {
case .extendedQuery(var extendedQuery, let connectionContext):
return self.avoidingStateMachineCoW { machine -> ConnectionAction in
Expand All @@ -500,11 +500,11 @@ struct ConnectionStateMachine {
}
}

mutating func notificationReceived(_ notification: PSQLBackendMessage.NotificationResponse) -> ConnectionAction {
mutating func notificationReceived(_ notification: PostgresBackendMessage.NotificationResponse) -> ConnectionAction {
return .forwardNotificationToListeners(notification)
}

mutating func readyForQueryReceived(_ transactionState: PSQLBackendMessage.TransactionState) -> ConnectionAction {
mutating func readyForQueryReceived(_ transactionState: PostgresBackendMessage.TransactionState) -> ConnectionAction {
switch self.state {
case .authenticated(let backendKeyData, let parameters):
guard let keyData = backendKeyData else {
Expand Down Expand Up @@ -694,7 +694,7 @@ struct ConnectionStateMachine {
}
}

mutating func parameterDescriptionReceived(_ description: PSQLBackendMessage.ParameterDescription) -> ConnectionAction {
mutating func parameterDescriptionReceived(_ description: PostgresBackendMessage.ParameterDescription) -> ConnectionAction {
switch self.state {
case .extendedQuery(var queryState, let connectionContext) where !queryState.isComplete:
return self.avoidingStateMachineCoW { machine -> ConnectionAction in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct ExtendedQueryStateMachine {
}
}

mutating func parameterDescriptionReceived(_ parameterDescription: PSQLBackendMessage.ParameterDescription) -> Action {
mutating func parameterDescriptionReceived(_ parameterDescription: PostgresBackendMessage.ParameterDescription) -> Action {
guard case .parseCompleteReceived(let queryContext) = self.state else {
return self.setAndFireError(.unexpectedBackendMessage(.parameterDescription(parameterDescription)))
}
Expand Down Expand Up @@ -217,7 +217,7 @@ struct ExtendedQueryStateMachine {
preconditionFailure("Unimplemented")
}

mutating func errorReceived(_ errorMessage: PSQLBackendMessage.ErrorResponse) -> Action {
mutating func errorReceived(_ errorMessage: PostgresBackendMessage.ErrorResponse) -> Action {
let error = PSQLError.server(errorMessage)
switch self.state {
case .initialized:
Expand All @@ -244,7 +244,7 @@ struct ExtendedQueryStateMachine {
}
}

mutating func noticeReceived(_ notice: PSQLBackendMessage.NoticeResponse) -> Action {
mutating func noticeReceived(_ notice: PostgresBackendMessage.NoticeResponse) -> Action {
//self.queryObject.noticeReceived(notice)
return .wait
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct PrepareStatementStateMachine {
return .wait
}

mutating func parameterDescriptionReceived(_ parameterDescription: PSQLBackendMessage.ParameterDescription) -> Action {
mutating func parameterDescriptionReceived(_ parameterDescription: PostgresBackendMessage.ParameterDescription) -> Action {
guard case .parseCompleteReceived(let createContext) = self.state else {
return self.setAndFireError(.unexpectedBackendMessage(.parameterDescription(parameterDescription)))
}
Expand All @@ -81,7 +81,7 @@ struct PrepareStatementStateMachine {
return .succeedPreparedStatementCreation(queryContext, with: rowDescription)
}

mutating func errorReceived(_ errorMessage: PSQLBackendMessage.ErrorResponse) -> Action {
mutating func errorReceived(_ errorMessage: PostgresBackendMessage.ErrorResponse) -> Action {
let error = PSQLError.server(errorMessage)
switch self.state {
case .initialized:
Expand Down
2 changes: 1 addition & 1 deletion Sources/PostgresNIO/New/Extensions/ByteBuffer+PSQL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import NIOCore

internal extension ByteBuffer {

mutating func psqlWriteBackendMessageID(_ messageID: PSQLBackendMessage.ID) {
mutating func psqlWriteBackendMessageID(_ messageID: PostgresBackendMessage.ID) {
self.writeInteger(messageID.rawValue)
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/PostgresNIO/New/Messages/Authentication.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import NIOCore

extension PSQLBackendMessage {
extension PostgresBackendMessage {

enum Authentication: PayloadDecodable {
case ok
Expand Down Expand Up @@ -61,7 +61,7 @@ extension PSQLBackendMessage {
}
}

extension PSQLBackendMessage.Authentication: Equatable {
extension PostgresBackendMessage.Authentication: Equatable {
static func ==(lhs: Self, rhs: Self) -> Bool {
switch (lhs, rhs) {
case (.ok, .ok):
Expand Down Expand Up @@ -92,7 +92,7 @@ extension PSQLBackendMessage.Authentication: Equatable {
}
}

extension PSQLBackendMessage.Authentication: CustomDebugStringConvertible {
extension PostgresBackendMessage.Authentication: CustomDebugStringConvertible {
var debugDescription: String {
switch self {
case .ok:
Expand Down
4 changes: 2 additions & 2 deletions Sources/PostgresNIO/New/Messages/BackendKeyData.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import NIOCore

extension PSQLBackendMessage {
extension PostgresBackendMessage {

struct BackendKeyData: PayloadDecodable, Equatable {
let processID: Int32
Expand All @@ -16,7 +16,7 @@ extension PSQLBackendMessage {
}
}

extension PSQLBackendMessage.BackendKeyData: CustomDebugStringConvertible {
extension PostgresBackendMessage.BackendKeyData: CustomDebugStringConvertible {
var debugDescription: String {
"processID: \(processID), secretKey: \(secretKey)"
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/PostgresNIO/New/Messages/DataRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import NIOCore
/// enclosing type, the enclosing type must be @usableFromInline as well.
/// Not putting `DataRow` in ``PSQLBackendMessage`` is our way to trick
/// the Swift compiler
struct DataRow: PSQLBackendMessage.PayloadDecodable, Equatable {
struct DataRow: PostgresBackendMessage.PayloadDecodable, Equatable {

var columnCount: Int16

Expand Down
24 changes: 12 additions & 12 deletions Sources/PostgresNIO/New/Messages/ErrorResponse.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import NIOCore

extension PSQLBackendMessage {
extension PostgresBackendMessage {

enum Field: UInt8, Hashable {
/// Severity: the field contents are ERROR, FATAL, or PANIC (in an error message),
Expand Down Expand Up @@ -81,40 +81,40 @@ extension PSQLBackendMessage {
}

struct ErrorResponse: PSQLMessageNotice, PayloadDecodable, Equatable {
let fields: [PSQLBackendMessage.Field: String]
let fields: [PostgresBackendMessage.Field: String]

init(fields: [PSQLBackendMessage.Field: String]) {
init(fields: [PostgresBackendMessage.Field: String]) {
self.fields = fields
}
}

struct NoticeResponse: PSQLMessageNotice, PayloadDecodable, Equatable {
let fields: [PSQLBackendMessage.Field: String]
let fields: [PostgresBackendMessage.Field: String]

init(fields: [PSQLBackendMessage.Field: String]) {
init(fields: [PostgresBackendMessage.Field: String]) {
self.fields = fields
}
}
}

protocol PSQLMessageNotice {
var fields: [PSQLBackendMessage.Field: String] { get }
var fields: [PostgresBackendMessage.Field: String] { get }

init(fields: [PSQLBackendMessage.Field: String])
init(fields: [PostgresBackendMessage.Field: String])
}

extension PSQLBackendMessage.PayloadDecodable where Self: PSQLMessageNotice {
extension PostgresBackendMessage.PayloadDecodable where Self: PSQLMessageNotice {

static func decode(from buffer: inout ByteBuffer) throws -> Self {
var fields: [PSQLBackendMessage.Field: String] = [:]
var fields: [PostgresBackendMessage.Field: String] = [:]
while let id = buffer.readInteger(as: UInt8.self) {
if id == 0 {
break
}
guard let field = PSQLBackendMessage.Field(rawValue: id) else {
guard let field = PostgresBackendMessage.Field(rawValue: id) else {
throw PSQLPartialDecodingError.valueNotRawRepresentable(
value: id,
asType: PSQLBackendMessage.Field.self)
asType: PostgresBackendMessage.Field.self)
}

guard let string = buffer.readNullTerminatedString() else {
Expand All @@ -126,7 +126,7 @@ extension PSQLBackendMessage.PayloadDecodable where Self: PSQLMessageNotice {
}
}

extension PSQLBackendMessage.Field: CustomStringConvertible {
extension PostgresBackendMessage.Field: CustomStringConvertible {

var description: String {
switch self {
Expand Down
4 changes: 2 additions & 2 deletions Sources/PostgresNIO/New/Messages/NotificationResponse.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import NIOCore

extension PSQLBackendMessage {
extension PostgresBackendMessage {

struct NotificationResponse: PayloadDecodable, Equatable {
let backendPID: Int32
let channel: String
let payload: String

static func decode(from buffer: inout ByteBuffer) throws -> PSQLBackendMessage.NotificationResponse {
static func decode(from buffer: inout ByteBuffer) throws -> PostgresBackendMessage.NotificationResponse {
let backendPID = try buffer.throwingReadInteger(as: Int32.self)

guard let channel = buffer.readNullTerminatedString() else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import NIOCore

extension PSQLBackendMessage {
extension PostgresBackendMessage {

struct ParameterDescription: PayloadDecodable, Equatable {
/// Specifies the object ID of the parameter data type.
Expand Down
4 changes: 2 additions & 2 deletions Sources/PostgresNIO/New/Messages/ParameterStatus.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import NIOCore

extension PSQLBackendMessage {
extension PostgresBackendMessage {

struct ParameterStatus: PayloadDecodable, Equatable {
/// The name of the run-time parameter being reported.
Expand All @@ -23,7 +23,7 @@ extension PSQLBackendMessage {
}
}

extension PSQLBackendMessage.ParameterStatus: CustomDebugStringConvertible {
extension PostgresBackendMessage.ParameterStatus: CustomDebugStringConvertible {
var debugDescription: String {
"parameter: \(String(reflecting: self.parameter)), value: \(String(reflecting: self.value))"
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/PostgresNIO/New/Messages/ReadyForQuery.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import NIOCore

extension PSQLBackendMessage {
extension PostgresBackendMessage {
enum TransactionState: PayloadDecodable, RawRepresentable {
typealias RawValue = UInt8

Expand Down Expand Up @@ -43,7 +43,7 @@ extension PSQLBackendMessage {
}
}

extension PSQLBackendMessage.TransactionState: CustomDebugStringConvertible {
extension PostgresBackendMessage.TransactionState: CustomDebugStringConvertible {
var debugDescription: String {
switch self {
case .idle:
Expand Down
2 changes: 1 addition & 1 deletion Sources/PostgresNIO/New/Messages/RowDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import NIOCore
/// enclosing type, the enclosing type must be @usableFromInline as well.
/// Not putting `DataRow` in ``PSQLBackendMessage`` is our way to trick
/// the Swift compiler.
struct RowDescription: PSQLBackendMessage.PayloadDecodable, Equatable {
struct RowDescription: PostgresBackendMessage.PayloadDecodable, Equatable {
/// Specifies the object ID of the parameter data type.
var columns: [Column]

Expand Down
Loading