Skip to content

Commit 4376f4e

Browse files
authored
feat: BREAKING - Parse unknown types as string (#238)
1 parent 1ba5db3 commit 4376f4e

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

decode.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,11 @@ function decodeText(value: Uint8Array, typeOid: number): any {
167167
case Oid.timestamptz_array:
168168
return decodeDatetimeArray(strValue);
169169
default:
170-
throw new Error(`Don't know how to parse column type: ${typeOid}`);
170+
// A separate category for not handled values
171+
// They might or might not be represented correctly as strings,
172+
// returning them to the user as raw strings allows them to parse
173+
// them as they see fit
174+
return strValue;
171175
}
172176
}
173177

tests/data_types.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,3 +890,17 @@ testClient(async function circleArray() {
890890

891891
assertEquals(rows[0][0][0], { point, radius });
892892
});
893+
894+
testClient(async function unhandledType() {
895+
const { rows: exists } = await CLIENT.queryArray(
896+
"SELECT EXISTS (SELECT TRUE FROM PG_TYPE WHERE UPPER(TYPNAME) = 'DIRECTION')",
897+
);
898+
if (exists[0][0]) {
899+
await CLIENT.queryArray("DROP TYPE DIRECTION;");
900+
}
901+
await CLIENT.queryArray("CREATE TYPE DIRECTION AS ENUM ( 'LEFT', 'RIGHT' )");
902+
const { rows: result } = await CLIENT.queryArray("SELECT 'LEFT'::DIRECTION;");
903+
await CLIENT.queryArray("DROP TYPE DIRECTION;");
904+
905+
assertEquals(result[0][0], "LEFT");
906+
});

0 commit comments

Comments
 (0)