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
32 changes: 21 additions & 11 deletions Sources/PostgresNIO/Connection/PostgresRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,6 @@ final class PostgresRequestHandler: ChannelDuplexHandler {
}
}

private func _write(context: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise<Void>?) throws {
let request = self.unwrapOutboundIn(data)
self.queue.append(request)
let messages = try request.delegate.start()
for message in messages {
context.write(self.wrapOutboundOut(message), promise: nil)
}
context.flush()
}

func channelRead(context: ChannelHandlerContext, data: NIOAny) {
do {
try self._channelRead(context: context, data: data)
Expand All @@ -95,9 +85,14 @@ final class PostgresRequestHandler: ChannelDuplexHandler {
}

func write(context: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise<Void>?) {
let request = self.unwrapOutboundIn(data)
self.queue.append(request)
do {
try self._write(context: context, data: data, promise: promise)
let messages = try request.delegate.start()
self.write(context: context, items: messages, promise: promise)
context.flush()
} catch {
promise?.fail(error)
self.errorCaught(context: context, error: error)
}
}
Expand All @@ -110,3 +105,18 @@ final class PostgresRequestHandler: ChannelDuplexHandler {
context.close(mode: mode, promise: promise)
}
}


extension ChannelInboundHandler {
func write(context: ChannelHandlerContext, items: [OutboundOut], promise: EventLoopPromise<Void>?) {
var items = items
if let last = items.popLast() {
for item in items {
context.write(self.wrapOutboundOut(item), promise: nil)
}
context.write(self.wrapOutboundOut(last), promise: promise)
} else {
promise?.succeed(())
}
}
}
17 changes: 17 additions & 0 deletions Sources/PostgresNIO/Data/PostgresData+Double.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,20 @@ extension PostgresData {
}
}
}

extension Double: PostgresDataConvertible {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this and the change below seem unrelated?

public static var postgresDataType: PostgresDataType {
return .float8
}

public init?(postgresData: PostgresData) {
guard let double = postgresData.double else {
return nil
}
self = double
}

public var postgresData: PostgresData? {
return .init(double: self)
}
}
17 changes: 17 additions & 0 deletions Sources/PostgresNIO/Data/PostgresData+Float.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,20 @@ extension PostgresData {
}
}
}

extension Float: PostgresDataConvertible {
public static var postgresDataType: PostgresDataType {
return .float4
}

public init?(postgresData: PostgresData) {
guard let float = postgresData.float else {
return nil
}
self = float
}

public var postgresData: PostgresData? {
return .init(float: self)
}
}