From 77ed8afe32d4fe5845f559642af6c7b3517d3279 Mon Sep 17 00:00:00 2001 From: Fabian Fett Date: Thu, 17 Feb 2022 23:31:09 +0100 Subject: [PATCH 1/2] Make PSQLDecodingContext generic --- .../New/Data/Array+PSQLCodable.swift | 7 +++- .../New/Data/Bool+PSQLCodable.swift | 7 +++- .../New/Data/Bytes+PSQLCodable.swift | 14 ++++++-- .../New/Data/Date+PSQLCodable.swift | 7 +++- .../New/Data/Decimal+PSQLCodable.swift | 7 +++- .../New/Data/Float+PSQLCodable.swift | 14 ++++++-- .../New/Data/Int+PSQLCodable.swift | 35 +++++++++++++++--- .../New/Data/JSON+PSQLCodable.swift | 7 +++- .../New/Data/Optional+PSQLCodable.swift | 14 ++++---- .../Data/RawRepresentable+PSQLCodable.swift | 7 +++- .../New/Data/String+PSQLCodable.swift | 7 +++- .../New/Data/UUID+PSQLCodable.swift | 7 +++- Sources/PostgresNIO/New/PSQLCodable.swift | 36 +++++++++---------- Sources/PostgresNIO/New/PSQLRow.swift | 7 +--- Sources/PostgresNIO/Postgres+PSQLCompat.swift | 7 +++- .../New/Extensions/PSQLCoding+TestUtils.swift | 6 ++-- 16 files changed, 135 insertions(+), 54 deletions(-) diff --git a/Sources/PostgresNIO/New/Data/Array+PSQLCodable.swift b/Sources/PostgresNIO/New/Data/Array+PSQLCodable.swift index ba89bbb8..4001579a 100644 --- a/Sources/PostgresNIO/New/Data/Array+PSQLCodable.swift +++ b/Sources/PostgresNIO/New/Data/Array+PSQLCodable.swift @@ -101,7 +101,12 @@ extension Array: PSQLEncodable where Element: PSQLArrayElement { } extension Array: PSQLDecodable where Element: PSQLArrayElement { - static func decode(from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, context: PSQLDecodingContext) throws -> Array { + static func decode( + from buffer: inout ByteBuffer, + type: PostgresDataType, + format: PostgresFormat, + context: PSQLDecodingContext + ) throws -> Array { guard case .binary = format else { // currently we only support decoding arrays in binary format. throw PostgresCastingError.Code.failure diff --git a/Sources/PostgresNIO/New/Data/Bool+PSQLCodable.swift b/Sources/PostgresNIO/New/Data/Bool+PSQLCodable.swift index 3d7a6776..f2bb3eea 100644 --- a/Sources/PostgresNIO/New/Data/Bool+PSQLCodable.swift +++ b/Sources/PostgresNIO/New/Data/Bool+PSQLCodable.swift @@ -9,7 +9,12 @@ extension Bool: PSQLCodable { .binary } - static func decode(from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, context: PSQLDecodingContext) throws -> Bool { + static func decode( + from buffer: inout ByteBuffer, + type: PostgresDataType, + format: PostgresFormat, + context: PSQLDecodingContext + ) throws -> Self { guard type == .bool else { throw PostgresCastingError.Code.typeMismatch } diff --git a/Sources/PostgresNIO/New/Data/Bytes+PSQLCodable.swift b/Sources/PostgresNIO/New/Data/Bytes+PSQLCodable.swift index b359f3ca..e27575c9 100644 --- a/Sources/PostgresNIO/New/Data/Bytes+PSQLCodable.swift +++ b/Sources/PostgresNIO/New/Data/Bytes+PSQLCodable.swift @@ -30,7 +30,12 @@ extension ByteBuffer: PSQLCodable { byteBuffer.writeBuffer(©OfSelf) } - static func decode(from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, context: PSQLDecodingContext) throws -> Self { + static func decode( + from buffer: inout ByteBuffer, + type: PostgresDataType, + format: PostgresFormat, + context: PSQLDecodingContext + ) throws -> Self { return buffer } } @@ -48,7 +53,12 @@ extension Data: PSQLCodable { byteBuffer.writeBytes(self) } - static func decode(from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, context: PSQLDecodingContext) throws -> Self { + static func decode( + from buffer: inout ByteBuffer, + type: PostgresDataType, + format: PostgresFormat, + context: PSQLDecodingContext + ) throws -> Self { return buffer.readData(length: buffer.readableBytes, byteTransferStrategy: .automatic)! } } diff --git a/Sources/PostgresNIO/New/Data/Date+PSQLCodable.swift b/Sources/PostgresNIO/New/Data/Date+PSQLCodable.swift index 71201853..57dccfd8 100644 --- a/Sources/PostgresNIO/New/Data/Date+PSQLCodable.swift +++ b/Sources/PostgresNIO/New/Data/Date+PSQLCodable.swift @@ -10,7 +10,12 @@ extension Date: PSQLCodable { .binary } - static func decode(from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, context: PSQLDecodingContext) throws -> Self { + static func decode( + from buffer: inout ByteBuffer, + type: PostgresDataType, + format: PostgresFormat, + context: PSQLDecodingContext + ) throws -> Self { switch type { case .timestamp, .timestamptz: guard buffer.readableBytes == 8, let microseconds = buffer.readInteger(as: Int64.self) else { diff --git a/Sources/PostgresNIO/New/Data/Decimal+PSQLCodable.swift b/Sources/PostgresNIO/New/Data/Decimal+PSQLCodable.swift index 0a683e37..f11ec8ac 100644 --- a/Sources/PostgresNIO/New/Data/Decimal+PSQLCodable.swift +++ b/Sources/PostgresNIO/New/Data/Decimal+PSQLCodable.swift @@ -10,7 +10,12 @@ extension Decimal: PSQLCodable { .binary } - static func decode(from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, context: PSQLDecodingContext) throws -> Self { + static func decode( + from buffer: inout ByteBuffer, + type: PostgresDataType, + format: PostgresFormat, + context: PSQLDecodingContext + ) throws -> Self { switch (format, type) { case (.binary, .numeric): guard let numeric = PostgresNumeric(buffer: &buffer) else { diff --git a/Sources/PostgresNIO/New/Data/Float+PSQLCodable.swift b/Sources/PostgresNIO/New/Data/Float+PSQLCodable.swift index 0aab376f..71e90e83 100644 --- a/Sources/PostgresNIO/New/Data/Float+PSQLCodable.swift +++ b/Sources/PostgresNIO/New/Data/Float+PSQLCodable.swift @@ -9,7 +9,12 @@ extension Float: PSQLCodable { .binary } - static func decode(from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, context: PSQLDecodingContext) throws -> Self { + static func decode( + from buffer: inout ByteBuffer, + type: PostgresDataType, + format: PostgresFormat, + context: PSQLDecodingContext + ) throws -> Self { switch (format, type) { case (.binary, .float4): guard buffer.readableBytes == 4, let float = buffer.psqlReadFloat() else { @@ -45,7 +50,12 @@ extension Double: PSQLCodable { .binary } - static func decode(from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, context: PSQLDecodingContext) throws -> Self { + static func decode( + from buffer: inout ByteBuffer, + type: PostgresDataType, + format: PostgresFormat, + context: PSQLDecodingContext + ) throws -> Self { switch (format, type) { case (.binary, .float4): guard buffer.readableBytes == 4, let float = buffer.psqlReadFloat() else { diff --git a/Sources/PostgresNIO/New/Data/Int+PSQLCodable.swift b/Sources/PostgresNIO/New/Data/Int+PSQLCodable.swift index d63bb8eb..a6c0ad63 100644 --- a/Sources/PostgresNIO/New/Data/Int+PSQLCodable.swift +++ b/Sources/PostgresNIO/New/Data/Int+PSQLCodable.swift @@ -9,7 +9,12 @@ extension UInt8: PSQLCodable { .binary } - static func decode(from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, context: PSQLDecodingContext) throws -> Self { + static func decode( + from buffer: inout ByteBuffer, + type: PostgresDataType, + format: PostgresFormat, + context: PSQLDecodingContext + ) throws -> Self { switch type { case .bpchar, .char: guard buffer.readableBytes == 1, let value = buffer.readInteger(as: UInt8.self) else { @@ -37,7 +42,12 @@ extension Int16: PSQLCodable { .binary } - static func decode(from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, context: PSQLDecodingContext) throws -> Self { + static func decode( + from buffer: inout ByteBuffer, + type: PostgresDataType, + format: PostgresFormat, + context: PSQLDecodingContext + ) throws -> Self { switch (format, type) { case (.binary, .int2): guard buffer.readableBytes == 2, let value = buffer.readInteger(as: Int16.self) else { @@ -68,7 +78,12 @@ extension Int32: PSQLCodable { .binary } - static func decode(from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, context: PSQLDecodingContext) throws -> Self { + static func decode( + from buffer: inout ByteBuffer, + type: PostgresDataType, + format: PostgresFormat, + context: PSQLDecodingContext + ) throws -> Self { switch (format, type) { case (.binary, .int2): guard buffer.readableBytes == 2, let value = buffer.readInteger(as: Int16.self) else { @@ -104,7 +119,12 @@ extension Int64: PSQLCodable { .binary } - static func decode(from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, context: PSQLDecodingContext) throws -> Self { + static func decode( + from buffer: inout ByteBuffer, + type: PostgresDataType, + format: PostgresFormat, + context: PSQLDecodingContext + ) throws -> Self { switch (format, type) { case (.binary, .int2): guard buffer.readableBytes == 2, let value = buffer.readInteger(as: Int16.self) else { @@ -152,7 +172,12 @@ extension Int: PSQLCodable { .binary } - static func decode(from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, context: PSQLDecodingContext) throws -> Self { + static func decode( + from buffer: inout ByteBuffer, + type: PostgresDataType, + format: PostgresFormat, + context: PSQLDecodingContext + ) throws -> Self { switch (format, type) { case (.binary, .int2): guard buffer.readableBytes == 2, let value = buffer.readInteger(as: Int16.self) else { diff --git a/Sources/PostgresNIO/New/Data/JSON+PSQLCodable.swift b/Sources/PostgresNIO/New/Data/JSON+PSQLCodable.swift index 1500ce84..1d69ec50 100644 --- a/Sources/PostgresNIO/New/Data/JSON+PSQLCodable.swift +++ b/Sources/PostgresNIO/New/Data/JSON+PSQLCodable.swift @@ -14,7 +14,12 @@ extension PSQLCodable where Self: Codable { .binary } - static func decode(from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, context: PSQLDecodingContext) throws -> Self { + static func decode( + from buffer: inout ByteBuffer, + type: PostgresDataType, + format: PostgresFormat, + context: PSQLDecodingContext + ) throws -> Self { switch (format, type) { case (.binary, .jsonb): guard JSONBVersionByte == buffer.readInteger(as: UInt8.self) else { diff --git a/Sources/PostgresNIO/New/Data/Optional+PSQLCodable.swift b/Sources/PostgresNIO/New/Data/Optional+PSQLCodable.swift index a01d5f15..f31f98ee 100644 --- a/Sources/PostgresNIO/New/Data/Optional+PSQLCodable.swift +++ b/Sources/PostgresNIO/New/Data/Optional+PSQLCodable.swift @@ -3,27 +3,25 @@ import NIOCore extension Optional: PSQLDecodable where Wrapped: PSQLDecodable, Wrapped.DecodableType == Wrapped { typealias DecodableType = Wrapped - static func decode( + static func decode( from byteBuffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, - context: PSQLDecodingContext + context: PSQLDecodingContext ) throws -> Optional { preconditionFailure("This should not be called") } - static func decodeRaw( + static func decodeRaw( from byteBuffer: inout ByteBuffer?, type: PostgresDataType, format: PostgresFormat, - context: PSQLDecodingContext + context: PSQLDecodingContext ) throws -> Self { - switch byteBuffer { - case .some(var buffer): - return try DecodableType.decode(from: &buffer, type: type, format: format, context: context) - case .none: + guard var buffer = byteBuffer else { return nil } + return try DecodableType.decode(from: &buffer, type: type, format: format, context: context) } } diff --git a/Sources/PostgresNIO/New/Data/RawRepresentable+PSQLCodable.swift b/Sources/PostgresNIO/New/Data/RawRepresentable+PSQLCodable.swift index f8812da3..bcb285db 100644 --- a/Sources/PostgresNIO/New/Data/RawRepresentable+PSQLCodable.swift +++ b/Sources/PostgresNIO/New/Data/RawRepresentable+PSQLCodable.swift @@ -9,7 +9,12 @@ extension PSQLCodable where Self: RawRepresentable, RawValue: PSQLCodable { self.rawValue.psqlFormat } - static func decode(from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, context: PSQLDecodingContext) throws -> Self { + static func decode( + from buffer: inout ByteBuffer, + type: PostgresDataType, + format: PostgresFormat, + context: PSQLDecodingContext + ) throws -> Self { guard let rawValue = try? RawValue.decode(from: &buffer, type: type, format: format, context: context), let selfValue = Self.init(rawValue: rawValue) else { throw PostgresCastingError.Code.failure diff --git a/Sources/PostgresNIO/New/Data/String+PSQLCodable.swift b/Sources/PostgresNIO/New/Data/String+PSQLCodable.swift index d761fc48..1a3f3928 100644 --- a/Sources/PostgresNIO/New/Data/String+PSQLCodable.swift +++ b/Sources/PostgresNIO/New/Data/String+PSQLCodable.swift @@ -14,7 +14,12 @@ extension String: PSQLCodable { byteBuffer.writeString(self) } - static func decode(from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, context: PSQLDecodingContext) throws -> Self { + static func decode( + from buffer: inout ByteBuffer, + type: PostgresDataType, + format: PostgresFormat, + context: PSQLDecodingContext + ) throws -> Self { switch (format, type) { case (_, .varchar), (_, .text), diff --git a/Sources/PostgresNIO/New/Data/UUID+PSQLCodable.swift b/Sources/PostgresNIO/New/Data/UUID+PSQLCodable.swift index 0fdd2990..8ca52097 100644 --- a/Sources/PostgresNIO/New/Data/UUID+PSQLCodable.swift +++ b/Sources/PostgresNIO/New/Data/UUID+PSQLCodable.swift @@ -22,7 +22,12 @@ extension UUID: PSQLCodable { ]) } - static func decode(from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, context: PSQLDecodingContext) throws -> Self { + static func decode( + from buffer: inout ByteBuffer, + type: PostgresDataType, + format: PostgresFormat, + context: PSQLDecodingContext + ) throws -> Self { switch (format, type) { case (.binary, .uuid): guard let uuid = buffer.readUUID() else { diff --git a/Sources/PostgresNIO/New/PSQLCodable.swift b/Sources/PostgresNIO/New/PSQLCodable.swift index fbf3fbbb..b0443246 100644 --- a/Sources/PostgresNIO/New/PSQLCodable.swift +++ b/Sources/PostgresNIO/New/PSQLCodable.swift @@ -33,21 +33,31 @@ protocol PSQLDecodable { /// - context: A `PSQLDecodingContext` providing context for decoding. This includes a `JSONDecoder` /// to use when decoding json and metadata to create better errors. /// - Returns: A decoded object - static func decode(from byteBuffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, context: PSQLDecodingContext) throws -> Self + static func decode( + from byteBuffer: inout ByteBuffer, + type: PostgresDataType, + format: PostgresFormat, + context: PSQLDecodingContext + ) throws -> Self /// Decode an entity from the `byteBuffer` in postgres wire format. /// This method has a default implementation and may be overriden /// only for special cases, like `Optional`s. - static func decodeRaw(from byteBuffer: inout ByteBuffer?, type: PostgresDataType, format: PostgresFormat, context: PSQLDecodingContext) throws -> Self + static func decodeRaw( + from byteBuffer: inout ByteBuffer?, + type: PostgresDataType, + format: PostgresFormat, + context: PSQLDecodingContext + ) throws -> Self } extension PSQLDecodable { @inlinable - public static func decodeRaw( + static func decodeRaw( from byteBuffer: inout ByteBuffer?, type: PostgresDataType, format: PostgresFormat, - context: PSQLDecodingContext + context: PSQLDecodingContext ) throws -> Self { guard var buffer = byteBuffer else { throw PostgresCastingError.Code.missingData @@ -79,22 +89,10 @@ struct PSQLEncodingContext { let jsonEncoder: PostgresJSONEncoder } -struct PSQLDecodingContext { +struct PSQLDecodingContext { + let jsonDecoder: JSONDecoder - let jsonDecoder: PostgresJSONDecoder - - let columnIndex: Int - let columnName: String - - let file: String - let line: Int - - init(jsonDecoder: PostgresJSONDecoder, columnName: String, columnIndex: Int, file: String, line: Int) { + init(jsonDecoder: JSONDecoder) { self.jsonDecoder = jsonDecoder - self.columnName = columnName - self.columnIndex = columnIndex - - self.file = file - self.line = line } } diff --git a/Sources/PostgresNIO/New/PSQLRow.swift b/Sources/PostgresNIO/New/PSQLRow.swift index dbd57c48..3726ea02 100644 --- a/Sources/PostgresNIO/New/PSQLRow.swift +++ b/Sources/PostgresNIO/New/PSQLRow.swift @@ -48,12 +48,7 @@ extension PSQLRow { precondition(index < self.data.columnCount) let column = self.columns[index] - let context = PSQLDecodingContext( - jsonDecoder: jsonDecoder, - columnName: column.name, - columnIndex: index, - file: file, - line: line) + let context = PSQLDecodingContext(jsonDecoder: jsonDecoder) // Safe to force unwrap here, as we have ensured above that the row has enough columns var cellSlice = self.data[column: index]! diff --git a/Sources/PostgresNIO/Postgres+PSQLCompat.swift b/Sources/PostgresNIO/Postgres+PSQLCompat.swift index c0f7cef8..692968c6 100644 --- a/Sources/PostgresNIO/Postgres+PSQLCompat.swift +++ b/Sources/PostgresNIO/Postgres+PSQLCompat.swift @@ -26,7 +26,12 @@ extension PostgresData: PSQLEncodable { } extension PostgresData: PSQLDecodable { - static func decode(from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, context: PSQLDecodingContext) throws -> Self { + static func decode( + from buffer: inout ByteBuffer, + type: PostgresDataType, + format: PostgresFormat, + context: PSQLDecodingContext + ) throws -> Self { let myBuffer = buffer.readSlice(length: buffer.readableBytes)! return PostgresData(type: PostgresDataType(UInt32(type.rawValue)), typeModifier: nil, formatCode: .binary, value: myBuffer) diff --git a/Tests/PostgresNIOTests/New/Extensions/PSQLCoding+TestUtils.swift b/Tests/PostgresNIOTests/New/Extensions/PSQLCoding+TestUtils.swift index 602306d8..85076644 100644 --- a/Tests/PostgresNIOTests/New/Extensions/PSQLCoding+TestUtils.swift +++ b/Tests/PostgresNIOTests/New/Extensions/PSQLCoding+TestUtils.swift @@ -7,9 +7,9 @@ extension PSQLFrontendMessageEncoder { } } -extension PSQLDecodingContext { - static func forTests(columnName: String = "unknown", columnIndex: Int = 0, jsonDecoder: PostgresJSONDecoder = JSONDecoder(), file: String = #file, line: Int = #line) -> Self { - Self(jsonDecoder: JSONDecoder(), columnName: columnName, columnIndex: columnIndex, file: file, line: line) +extension PSQLDecodingContext where JSONDecoder == Foundation.JSONDecoder { + static func forTests() -> Self { + Self(jsonDecoder: JSONDecoder()) } } From 3bae40446d09689a28cac080e256e6fa37b3135c Mon Sep 17 00:00:00 2001 From: Fabian Fett Date: Thu, 17 Feb 2022 23:32:51 +0100 Subject: [PATCH 2/2] Rename to PostgresDecodingContext --- Sources/PostgresNIO/New/Data/Array+PSQLCodable.swift | 2 +- Sources/PostgresNIO/New/Data/Bool+PSQLCodable.swift | 2 +- Sources/PostgresNIO/New/Data/Bytes+PSQLCodable.swift | 4 ++-- Sources/PostgresNIO/New/Data/Date+PSQLCodable.swift | 2 +- Sources/PostgresNIO/New/Data/Decimal+PSQLCodable.swift | 2 +- Sources/PostgresNIO/New/Data/Float+PSQLCodable.swift | 4 ++-- Sources/PostgresNIO/New/Data/Int+PSQLCodable.swift | 10 +++++----- Sources/PostgresNIO/New/Data/JSON+PSQLCodable.swift | 2 +- .../PostgresNIO/New/Data/Optional+PSQLCodable.swift | 4 ++-- .../New/Data/RawRepresentable+PSQLCodable.swift | 2 +- Sources/PostgresNIO/New/Data/String+PSQLCodable.swift | 2 +- Sources/PostgresNIO/New/Data/UUID+PSQLCodable.swift | 2 +- Sources/PostgresNIO/New/PSQLCodable.swift | 8 ++++---- Sources/PostgresNIO/New/PSQLRow.swift | 2 +- Sources/PostgresNIO/Postgres+PSQLCompat.swift | 2 +- .../New/Extensions/PSQLCoding+TestUtils.swift | 2 +- 16 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Sources/PostgresNIO/New/Data/Array+PSQLCodable.swift b/Sources/PostgresNIO/New/Data/Array+PSQLCodable.swift index 4001579a..d74717f7 100644 --- a/Sources/PostgresNIO/New/Data/Array+PSQLCodable.swift +++ b/Sources/PostgresNIO/New/Data/Array+PSQLCodable.swift @@ -105,7 +105,7 @@ extension Array: PSQLDecodable where Element: PSQLArrayElement { from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, - context: PSQLDecodingContext + context: PostgresDecodingContext ) throws -> Array { guard case .binary = format else { // currently we only support decoding arrays in binary format. diff --git a/Sources/PostgresNIO/New/Data/Bool+PSQLCodable.swift b/Sources/PostgresNIO/New/Data/Bool+PSQLCodable.swift index f2bb3eea..d9896efe 100644 --- a/Sources/PostgresNIO/New/Data/Bool+PSQLCodable.swift +++ b/Sources/PostgresNIO/New/Data/Bool+PSQLCodable.swift @@ -13,7 +13,7 @@ extension Bool: PSQLCodable { from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, - context: PSQLDecodingContext + context: PostgresDecodingContext ) throws -> Self { guard type == .bool else { throw PostgresCastingError.Code.typeMismatch diff --git a/Sources/PostgresNIO/New/Data/Bytes+PSQLCodable.swift b/Sources/PostgresNIO/New/Data/Bytes+PSQLCodable.swift index e27575c9..8c5e96a5 100644 --- a/Sources/PostgresNIO/New/Data/Bytes+PSQLCodable.swift +++ b/Sources/PostgresNIO/New/Data/Bytes+PSQLCodable.swift @@ -34,7 +34,7 @@ extension ByteBuffer: PSQLCodable { from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, - context: PSQLDecodingContext + context: PostgresDecodingContext ) throws -> Self { return buffer } @@ -57,7 +57,7 @@ extension Data: PSQLCodable { from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, - context: PSQLDecodingContext + context: PostgresDecodingContext ) throws -> Self { return buffer.readData(length: buffer.readableBytes, byteTransferStrategy: .automatic)! } diff --git a/Sources/PostgresNIO/New/Data/Date+PSQLCodable.swift b/Sources/PostgresNIO/New/Data/Date+PSQLCodable.swift index 57dccfd8..05491a61 100644 --- a/Sources/PostgresNIO/New/Data/Date+PSQLCodable.swift +++ b/Sources/PostgresNIO/New/Data/Date+PSQLCodable.swift @@ -14,7 +14,7 @@ extension Date: PSQLCodable { from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, - context: PSQLDecodingContext + context: PostgresDecodingContext ) throws -> Self { switch type { case .timestamp, .timestamptz: diff --git a/Sources/PostgresNIO/New/Data/Decimal+PSQLCodable.swift b/Sources/PostgresNIO/New/Data/Decimal+PSQLCodable.swift index f11ec8ac..22c4785d 100644 --- a/Sources/PostgresNIO/New/Data/Decimal+PSQLCodable.swift +++ b/Sources/PostgresNIO/New/Data/Decimal+PSQLCodable.swift @@ -14,7 +14,7 @@ extension Decimal: PSQLCodable { from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, - context: PSQLDecodingContext + context: PostgresDecodingContext ) throws -> Self { switch (format, type) { case (.binary, .numeric): diff --git a/Sources/PostgresNIO/New/Data/Float+PSQLCodable.swift b/Sources/PostgresNIO/New/Data/Float+PSQLCodable.swift index 71e90e83..a3463c8e 100644 --- a/Sources/PostgresNIO/New/Data/Float+PSQLCodable.swift +++ b/Sources/PostgresNIO/New/Data/Float+PSQLCodable.swift @@ -13,7 +13,7 @@ extension Float: PSQLCodable { from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, - context: PSQLDecodingContext + context: PostgresDecodingContext ) throws -> Self { switch (format, type) { case (.binary, .float4): @@ -54,7 +54,7 @@ extension Double: PSQLCodable { from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, - context: PSQLDecodingContext + context: PostgresDecodingContext ) throws -> Self { switch (format, type) { case (.binary, .float4): diff --git a/Sources/PostgresNIO/New/Data/Int+PSQLCodable.swift b/Sources/PostgresNIO/New/Data/Int+PSQLCodable.swift index a6c0ad63..49284a8a 100644 --- a/Sources/PostgresNIO/New/Data/Int+PSQLCodable.swift +++ b/Sources/PostgresNIO/New/Data/Int+PSQLCodable.swift @@ -13,7 +13,7 @@ extension UInt8: PSQLCodable { from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, - context: PSQLDecodingContext + context: PostgresDecodingContext ) throws -> Self { switch type { case .bpchar, .char: @@ -46,7 +46,7 @@ extension Int16: PSQLCodable { from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, - context: PSQLDecodingContext + context: PostgresDecodingContext ) throws -> Self { switch (format, type) { case (.binary, .int2): @@ -82,7 +82,7 @@ extension Int32: PSQLCodable { from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, - context: PSQLDecodingContext + context: PostgresDecodingContext ) throws -> Self { switch (format, type) { case (.binary, .int2): @@ -123,7 +123,7 @@ extension Int64: PSQLCodable { from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, - context: PSQLDecodingContext + context: PostgresDecodingContext ) throws -> Self { switch (format, type) { case (.binary, .int2): @@ -176,7 +176,7 @@ extension Int: PSQLCodable { from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, - context: PSQLDecodingContext + context: PostgresDecodingContext ) throws -> Self { switch (format, type) { case (.binary, .int2): diff --git a/Sources/PostgresNIO/New/Data/JSON+PSQLCodable.swift b/Sources/PostgresNIO/New/Data/JSON+PSQLCodable.swift index 1d69ec50..47aff5bf 100644 --- a/Sources/PostgresNIO/New/Data/JSON+PSQLCodable.swift +++ b/Sources/PostgresNIO/New/Data/JSON+PSQLCodable.swift @@ -18,7 +18,7 @@ extension PSQLCodable where Self: Codable { from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, - context: PSQLDecodingContext + context: PostgresDecodingContext ) throws -> Self { switch (format, type) { case (.binary, .jsonb): diff --git a/Sources/PostgresNIO/New/Data/Optional+PSQLCodable.swift b/Sources/PostgresNIO/New/Data/Optional+PSQLCodable.swift index f31f98ee..fef7d9d2 100644 --- a/Sources/PostgresNIO/New/Data/Optional+PSQLCodable.swift +++ b/Sources/PostgresNIO/New/Data/Optional+PSQLCodable.swift @@ -7,7 +7,7 @@ extension Optional: PSQLDecodable where Wrapped: PSQLDecodable, Wrapped.Decodabl from byteBuffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, - context: PSQLDecodingContext + context: PostgresDecodingContext ) throws -> Optional { preconditionFailure("This should not be called") } @@ -16,7 +16,7 @@ extension Optional: PSQLDecodable where Wrapped: PSQLDecodable, Wrapped.Decodabl from byteBuffer: inout ByteBuffer?, type: PostgresDataType, format: PostgresFormat, - context: PSQLDecodingContext + context: PostgresDecodingContext ) throws -> Self { guard var buffer = byteBuffer else { return nil diff --git a/Sources/PostgresNIO/New/Data/RawRepresentable+PSQLCodable.swift b/Sources/PostgresNIO/New/Data/RawRepresentable+PSQLCodable.swift index bcb285db..2036fef6 100644 --- a/Sources/PostgresNIO/New/Data/RawRepresentable+PSQLCodable.swift +++ b/Sources/PostgresNIO/New/Data/RawRepresentable+PSQLCodable.swift @@ -13,7 +13,7 @@ extension PSQLCodable where Self: RawRepresentable, RawValue: PSQLCodable { from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, - context: PSQLDecodingContext + context: PostgresDecodingContext ) throws -> Self { guard let rawValue = try? RawValue.decode(from: &buffer, type: type, format: format, context: context), let selfValue = Self.init(rawValue: rawValue) else { diff --git a/Sources/PostgresNIO/New/Data/String+PSQLCodable.swift b/Sources/PostgresNIO/New/Data/String+PSQLCodable.swift index 1a3f3928..66f4a400 100644 --- a/Sources/PostgresNIO/New/Data/String+PSQLCodable.swift +++ b/Sources/PostgresNIO/New/Data/String+PSQLCodable.swift @@ -18,7 +18,7 @@ extension String: PSQLCodable { from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, - context: PSQLDecodingContext + context: PostgresDecodingContext ) throws -> Self { switch (format, type) { case (_, .varchar), diff --git a/Sources/PostgresNIO/New/Data/UUID+PSQLCodable.swift b/Sources/PostgresNIO/New/Data/UUID+PSQLCodable.swift index 8ca52097..b258473b 100644 --- a/Sources/PostgresNIO/New/Data/UUID+PSQLCodable.swift +++ b/Sources/PostgresNIO/New/Data/UUID+PSQLCodable.swift @@ -26,7 +26,7 @@ extension UUID: PSQLCodable { from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, - context: PSQLDecodingContext + context: PostgresDecodingContext ) throws -> Self { switch (format, type) { case (.binary, .uuid): diff --git a/Sources/PostgresNIO/New/PSQLCodable.swift b/Sources/PostgresNIO/New/PSQLCodable.swift index b0443246..4b5dd041 100644 --- a/Sources/PostgresNIO/New/PSQLCodable.swift +++ b/Sources/PostgresNIO/New/PSQLCodable.swift @@ -37,7 +37,7 @@ protocol PSQLDecodable { from byteBuffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, - context: PSQLDecodingContext + context: PostgresDecodingContext ) throws -> Self /// Decode an entity from the `byteBuffer` in postgres wire format. @@ -47,7 +47,7 @@ protocol PSQLDecodable { from byteBuffer: inout ByteBuffer?, type: PostgresDataType, format: PostgresFormat, - context: PSQLDecodingContext + context: PostgresDecodingContext ) throws -> Self } @@ -57,7 +57,7 @@ extension PSQLDecodable { from byteBuffer: inout ByteBuffer?, type: PostgresDataType, format: PostgresFormat, - context: PSQLDecodingContext + context: PostgresDecodingContext ) throws -> Self { guard var buffer = byteBuffer else { throw PostgresCastingError.Code.missingData @@ -89,7 +89,7 @@ struct PSQLEncodingContext { let jsonEncoder: PostgresJSONEncoder } -struct PSQLDecodingContext { +struct PostgresDecodingContext { let jsonDecoder: JSONDecoder init(jsonDecoder: JSONDecoder) { diff --git a/Sources/PostgresNIO/New/PSQLRow.swift b/Sources/PostgresNIO/New/PSQLRow.swift index 3726ea02..c86f62a1 100644 --- a/Sources/PostgresNIO/New/PSQLRow.swift +++ b/Sources/PostgresNIO/New/PSQLRow.swift @@ -48,7 +48,7 @@ extension PSQLRow { precondition(index < self.data.columnCount) let column = self.columns[index] - let context = PSQLDecodingContext(jsonDecoder: jsonDecoder) + let context = PostgresDecodingContext(jsonDecoder: jsonDecoder) // Safe to force unwrap here, as we have ensured above that the row has enough columns var cellSlice = self.data[column: index]! diff --git a/Sources/PostgresNIO/Postgres+PSQLCompat.swift b/Sources/PostgresNIO/Postgres+PSQLCompat.swift index 692968c6..84bf7e56 100644 --- a/Sources/PostgresNIO/Postgres+PSQLCompat.swift +++ b/Sources/PostgresNIO/Postgres+PSQLCompat.swift @@ -30,7 +30,7 @@ extension PostgresData: PSQLDecodable { from buffer: inout ByteBuffer, type: PostgresDataType, format: PostgresFormat, - context: PSQLDecodingContext + context: PostgresDecodingContext ) throws -> Self { let myBuffer = buffer.readSlice(length: buffer.readableBytes)! diff --git a/Tests/PostgresNIOTests/New/Extensions/PSQLCoding+TestUtils.swift b/Tests/PostgresNIOTests/New/Extensions/PSQLCoding+TestUtils.swift index 85076644..3c83ac1f 100644 --- a/Tests/PostgresNIOTests/New/Extensions/PSQLCoding+TestUtils.swift +++ b/Tests/PostgresNIOTests/New/Extensions/PSQLCoding+TestUtils.swift @@ -7,7 +7,7 @@ extension PSQLFrontendMessageEncoder { } } -extension PSQLDecodingContext where JSONDecoder == Foundation.JSONDecoder { +extension PostgresDecodingContext where JSONDecoder == Foundation.JSONDecoder { static func forTests() -> Self { Self(jsonDecoder: JSONDecoder()) }