Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ struct ConnectionStateMachine {
// --- general actions
case sendParseDescribeBindExecuteSync(query: String, binds: [PSQLEncodable])
case sendBindExecuteSync(statementName: String, binds: [PSQLEncodable])
case failQuery(ExecuteExtendedQueryContext, with: PSQLError, cleanupContext: CleanUpContext?)
case succeedQuery(ExecuteExtendedQueryContext, columns: [PSQLBackendMessage.RowDescription.Column])
case succeedQueryNoRowsComming(ExecuteExtendedQueryContext, commandTag: String)
case failQuery(ExtendedQueryContext, with: PSQLError, cleanupContext: CleanUpContext?)
case succeedQuery(ExtendedQueryContext, columns: [PSQLBackendMessage.RowDescription.Column])
case succeedQueryNoRowsComming(ExtendedQueryContext, commandTag: String)

// --- streaming actions
// actions if query has requested next row but we are waiting for backend
Expand All @@ -100,8 +100,8 @@ struct ConnectionStateMachine {

// Prepare statement actions
case sendParseDescribeSync(name: String, query: String)
case succeedPreparedStatementCreation(CreatePreparedStatementContext, with: PSQLBackendMessage.RowDescription?)
case failPreparedStatementCreation(CreatePreparedStatementContext, with: PSQLError, cleanupContext: CleanUpContext?)
case succeedPreparedStatementCreation(PrepareStatementContext, with: PSQLBackendMessage.RowDescription?)
case failPreparedStatementCreation(PrepareStatementContext, with: PSQLError, cleanupContext: CleanUpContext?)

// Close actions
case sendCloseSync(CloseTarget)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
struct ExtendedQueryStateMachine {

enum State {
case initialized(ExecuteExtendedQueryContext)
case parseDescribeBindExecuteSyncSent(ExecuteExtendedQueryContext)
case initialized(ExtendedQueryContext)
case parseDescribeBindExecuteSyncSent(ExtendedQueryContext)

case parseCompleteReceived(ExecuteExtendedQueryContext)
case parameterDescriptionReceived(ExecuteExtendedQueryContext)
case rowDescriptionReceived(ExecuteExtendedQueryContext, [PSQLBackendMessage.RowDescription.Column])
case noDataMessageReceived(ExecuteExtendedQueryContext)
case parseCompleteReceived(ExtendedQueryContext)
case parameterDescriptionReceived(ExtendedQueryContext)
case rowDescriptionReceived(ExtendedQueryContext, [PSQLBackendMessage.RowDescription.Column])
case noDataMessageReceived(ExtendedQueryContext)

/// A state that is used if a noData message was received before. If a row description was received `bufferingRows` is
/// used after receiving a `bindComplete` message
case bindCompleteReceived(ExecuteExtendedQueryContext)
case bindCompleteReceived(ExtendedQueryContext)
case bufferingRows([PSQLBackendMessage.RowDescription.Column], CircularBuffer<[PSQLData]>, readOnEmpty: Bool)
case waitingForNextRow([PSQLBackendMessage.RowDescription.Column], CircularBuffer<[PSQLData]>, EventLoopPromise<StateMachineStreamNextResult>)

Expand All @@ -27,9 +27,9 @@ struct ExtendedQueryStateMachine {
case sendBindExecuteSync(statementName: String, binds: [PSQLEncodable])

// --- general actions
case failQuery(ExecuteExtendedQueryContext, with: PSQLError)
case succeedQuery(ExecuteExtendedQueryContext, columns: [PSQLBackendMessage.RowDescription.Column])
case succeedQueryNoRowsComming(ExecuteExtendedQueryContext, commandTag: String)
case failQuery(ExtendedQueryContext, with: PSQLError)
case succeedQuery(ExtendedQueryContext, columns: [PSQLBackendMessage.RowDescription.Column])
case succeedQueryNoRowsComming(ExtendedQueryContext, commandTag: String)

// --- streaming actions
// actions if query has requested next row but we are waiting for backend
Expand All @@ -46,7 +46,7 @@ struct ExtendedQueryStateMachine {

var state: State

init(queryContext: ExecuteExtendedQueryContext) {
init(queryContext: ExtendedQueryContext) {
self.state = .initialized(queryContext)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
struct PrepareStatementStateMachine {

enum State {
case initialized(CreatePreparedStatementContext)
case parseDescribeSent(CreatePreparedStatementContext)
case initialized(PrepareStatementContext)
case parseDescribeSent(PrepareStatementContext)

case parseCompleteReceived(CreatePreparedStatementContext)
case parameterDescriptionReceived(CreatePreparedStatementContext)
case parseCompleteReceived(PrepareStatementContext)
case parameterDescriptionReceived(PrepareStatementContext)
case rowDescriptionReceived
case noDataMessageReceived

Expand All @@ -15,16 +15,16 @@ struct PrepareStatementStateMachine {

enum Action {
case sendParseDescribeSync(name: String, query: String)
case succeedPreparedStatementCreation(CreatePreparedStatementContext, with: PSQLBackendMessage.RowDescription?)
case failPreparedStatementCreation(CreatePreparedStatementContext, with: PSQLError)
case succeedPreparedStatementCreation(PrepareStatementContext, with: PSQLBackendMessage.RowDescription?)
case failPreparedStatementCreation(PrepareStatementContext, with: PSQLError)

case read
case wait
}

var state: State

init(createContext: CreatePreparedStatementContext) {
init(createContext: PrepareStatementContext) {
self.state = .initialized(createContext)
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/PostgresNIO/New/PSQLChannelHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ final class PSQLChannelHandler: ChannelDuplexHandler {
}

private func succeedQueryWithRowStream(
_ queryContext: ExecuteExtendedQueryContext,
_ queryContext: ExtendedQueryContext,
columns: [PSQLBackendMessage.RowDescription.Column],
context: ChannelHandlerContext)
{
Expand Down Expand Up @@ -448,7 +448,7 @@ final class PSQLChannelHandler: ChannelDuplexHandler {
}

private func succeedQueryWithoutRowStream(
_ queryContext: ExecuteExtendedQueryContext,
_ queryContext: ExtendedQueryContext,
commandTag: String,
context: ChannelHandlerContext)
{
Expand Down
6 changes: 3 additions & 3 deletions Sources/PostgresNIO/New/PSQLConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ final class PSQLConnection {
return self.channel.eventLoop.makeFailedFuture(PSQLError.tooManyParameters)
}
let promise = self.channel.eventLoop.makePromise(of: PSQLRows.self)
let context = ExecuteExtendedQueryContext(
let context = ExtendedQueryContext(
query: query,
bind: bind,
logger: logger,
Expand All @@ -151,7 +151,7 @@ final class PSQLConnection {

func prepareStatement(_ query: String, with name: String, logger: Logger) -> EventLoopFuture<PSQLPreparedStatement> {
let promise = self.channel.eventLoop.makePromise(of: PSQLBackendMessage.RowDescription?.self)
let context = CreatePreparedStatementContext(
let context = PrepareStatementContext(
name: name,
query: query,
logger: logger,
Expand All @@ -170,7 +170,7 @@ final class PSQLConnection {
return self.channel.eventLoop.makeFailedFuture(PSQLError.tooManyParameters)
}
let promise = self.channel.eventLoop.makePromise(of: PSQLRows.self)
let context = ExecuteExtendedQueryContext(
let context = ExtendedQueryContext(
preparedStatement: preparedStatement,
bind: bind,
logger: logger,
Expand Down
2 changes: 1 addition & 1 deletion Sources/PostgresNIO/New/PSQLRows.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class PSQLRows {
private let jsonDecoder: PSQLJSONDecoder

init(rowDescription: [PSQLBackendMessage.RowDescription.Column],
queryContext: ExecuteExtendedQueryContext,
queryContext: ExtendedQueryContext,
eventLoop: EventLoop,
cancel: @escaping () -> (),
next: @escaping () -> EventLoopFuture<StateMachineStreamNextResult>)
Expand Down
8 changes: 4 additions & 4 deletions Sources/PostgresNIO/New/PSQLTask.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
enum PSQLTask {
case extendedQuery(ExecuteExtendedQueryContext)
case preparedStatement(CreatePreparedStatementContext)
case extendedQuery(ExtendedQueryContext)
case preparedStatement(PrepareStatementContext)
case closeCommand(CloseCommandContext)

func failWithError(_ error: PSQLError) {
Expand All @@ -15,7 +15,7 @@ enum PSQLTask {
}
}

final class ExecuteExtendedQueryContext {
final class ExtendedQueryContext {
enum Query {
case unnamed(String)
case preparedStatement(name: String, rowDescription: PSQLBackendMessage.RowDescription?)
Expand Down Expand Up @@ -58,7 +58,7 @@ final class ExecuteExtendedQueryContext {

}

final class CreatePreparedStatementContext {
final class PrepareStatementContext {
let name: String
let query: String
let logger: Logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class ConnectionStateMachineTests: XCTestCase {
let queryPromise = eventLoopGroup.next().makePromise(of: PSQLRows.self)

var state = ConnectionStateMachine()
let extendedQueryContext = ExecuteExtendedQueryContext(
let extendedQueryContext = ExtendedQueryContext(
query: "Select version()",
bind: [],
logger: .psqlTest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ExtendedQueryStateMachineTests: XCTestCase {
let promise = EmbeddedEventLoop().makePromise(of: PSQLRows.self)
promise.fail(PSQLError.uncleanShutdown) // we don't care about the error at all.
let query = "DELETE FROM table WHERE id=$0"
let queryContext = ExecuteExtendedQueryContext(query: query, bind: [1], logger: logger, jsonDecoder: JSONDecoder(), promise: promise)
let queryContext = ExtendedQueryContext(query: query, bind: [1], logger: logger, jsonDecoder: JSONDecoder(), promise: promise)

XCTAssertEqual(state.enqueue(task: .extendedQuery(queryContext)), .sendParseDescribeBindExecuteSync(query: query, binds: [1]))
XCTAssertEqual(state.parseCompleteReceived(), .wait)
Expand All @@ -28,7 +28,7 @@ class ExtendedQueryStateMachineTests: XCTestCase {
let queryPromise = EmbeddedEventLoop().makePromise(of: PSQLRows.self)
queryPromise.fail(PSQLError.uncleanShutdown) // we don't care about the error at all.
let query = "SELECT version()"
let queryContext = ExecuteExtendedQueryContext(query: query, bind: [], logger: logger, jsonDecoder: JSONDecoder(), promise: queryPromise)
let queryContext = ExtendedQueryContext(query: query, bind: [], logger: logger, jsonDecoder: JSONDecoder(), promise: queryPromise)

XCTAssertEqual(state.enqueue(task: .extendedQuery(queryContext)), .sendParseDescribeBindExecuteSync(query: query, binds: []))
XCTAssertEqual(state.parseCompleteReceived(), .wait)
Expand Down Expand Up @@ -59,7 +59,7 @@ class ExtendedQueryStateMachineTests: XCTestCase {
let promise = EmbeddedEventLoop().makePromise(of: PSQLRows.self)
promise.fail(PSQLError.uncleanShutdown) // we don't care about the error at all.
let query = "DELETE FROM table WHERE id=$0"
let queryContext = ExecuteExtendedQueryContext(query: query, bind: [1], logger: logger, jsonDecoder: JSONDecoder(), promise: promise)
let queryContext = ExtendedQueryContext(query: query, bind: [1], logger: logger, jsonDecoder: JSONDecoder(), promise: promise)

XCTAssertEqual(state.enqueue(task: .extendedQuery(queryContext)), .sendParseDescribeBindExecuteSync(query: query, binds: [1]))
XCTAssertEqual(state.parseCompleteReceived(), .wait)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PrepareStatementStateMachineTests: XCTestCase {

let name = "haha"
let query = #"SELECT id FROM users WHERE id = $1 "#
let prepareStatementContext = CreatePreparedStatementContext(
let prepareStatementContext = PrepareStatementContext(
name: name, query: query, logger: .psqlTest, promise: promise)

XCTAssertEqual(state.enqueue(task: .preparedStatement(prepareStatementContext)),
Expand All @@ -36,7 +36,7 @@ class PrepareStatementStateMachineTests: XCTestCase {

let name = "haha"
let query = #"DELETE FROM users WHERE id = $1 "#
let prepareStatementContext = CreatePreparedStatementContext(
let prepareStatementContext = PrepareStatementContext(
name: name, query: query, logger: .psqlTest, promise: promise)

XCTAssertEqual(state.enqueue(task: .preparedStatement(prepareStatementContext)),
Expand Down