Skip to content

Commit 62080bf

Browse files
authored
Decode .bpchar as String (vapor#368)
* `.bpchar` is "blank-padded char", the low-level Postgres name for `character(N)` (the auto-padded form of `character varying`). `String`'s `PostgresCodable` conformance should thus recognize it. * Add .bpchar test and tell the invalid encoding test that `bpchar` is a string, for pity's sake.
1 parent b3e1881 commit 62080bf

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

Sources/PostgresNIO/New/Data/String+PostgresCodable.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extension String: PostgresDecodable {
3030
) throws {
3131
switch (format, type) {
3232
case (_, .varchar),
33+
(_, .bpchar),
3334
(_, .text),
3435
(_, .name):
3536
// we can force unwrap here, since this method only fails if there are not enough

Tests/PostgresNIOTests/New/Data/String+PSQLCodableTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class String_PSQLCodableTests: XCTestCase {
2020
buffer.writeString(expected)
2121

2222
let dataTypes: [PostgresDataType] = [
23-
.text, .varchar, .name
23+
.text, .varchar, .name, .bpchar
2424
]
2525

2626
for dataType in dataTypes {
@@ -33,7 +33,7 @@ class String_PSQLCodableTests: XCTestCase {
3333

3434
func testDecodeFailureFromInvalidType() {
3535
let buffer = ByteBuffer()
36-
let dataTypes: [PostgresDataType] = [.bool, .float4Array, .float8Array, .bpchar]
36+
let dataTypes: [PostgresDataType] = [.bool, .float4Array, .float8Array]
3737

3838
for dataType in dataTypes {
3939
var loopBuffer = buffer

0 commit comments

Comments
 (0)