Skip to content

Commit c860e4a

Browse files
authored
add untyped array methods to postgresdata + fix #42 (#67)
* add untyped array methods to PostgresData * test fluent integration * add test for #42
1 parent bf76940 commit c860e4a

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Sources/PostgresNIO/Data/PostgresData+Int.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ private extension PostgresData {
115115
switch self.formatCode {
116116
case .binary:
117117
switch self.type {
118+
case .char, .bpchar:
119+
assert(value.readableBytes == 1)
120+
guard let uint8 = value.getInteger(at: value.readerIndex, as: UInt8.self) else {
121+
return nil
122+
}
123+
return I(uint8)
118124
case .int2:
119125
assert(value.readableBytes == 2)
120126
guard let int16 = value.readInteger(as: Int16.self) else {

Tests/PostgresNIOTests/PostgresNIOTests.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,19 @@ final class PostgresNIOTests: XCTestCase {
979979
XCTAssertEqual(rows[0].column("doubles")?.array(of: Double.self), doubles)
980980
}
981981

982+
// https://github.com/vapor/postgres-nio/issues/42
983+
func testUInt8Serialization() throws {
984+
let conn = try PostgresConnection.test(on: eventLoop).wait()
985+
defer { try! conn.close().wait() }
986+
let rows = try conn.query("""
987+
select
988+
$1::char as int
989+
""", [
990+
.init(uint8: 5)
991+
]).wait()
992+
XCTAssertEqual(rows[0].column("int")?.uint8, 5)
993+
}
994+
982995
}
983996

984997

0 commit comments

Comments
 (0)