diff --git a/decode.ts b/decode.ts index 05151580..7bd7c7b8 100644 --- a/decode.ts +++ b/decode.ts @@ -177,6 +177,10 @@ function decodeByteaEscape(byteaStr: string): Uint8Array { return new Uint8Array(bytes); } +function decodeByteaArray(value: string): unknown[] { + return parseArray(value, decodeBytea); +} + const decoder = new TextDecoder(); // deno-lint-ignore no-explicit-any @@ -240,6 +244,8 @@ function decodeText(value: Uint8Array, typeOid: number): any { return decodeStringArray(strValue); case Oid.bool: return strValue[0] === "t"; + case Oid._bool: + return parseArray(strValue, (x) => x[0] === "t"); case Oid.int2: case Oid.int4: return decodeBaseTenInt(strValue); @@ -262,6 +268,8 @@ function decodeText(value: Uint8Array, typeOid: number): any { return decodeJsonArray(strValue); case Oid.bytea: return decodeBytea(strValue); + case Oid._bytea: + return decodeByteaArray(strValue); default: throw new Error(`Don't know how to parse column type: ${typeOid}`); } diff --git a/tests/data_types.ts b/tests/data_types.ts index 83c706c0..f57d88b1 100644 --- a/tests/data_types.ts +++ b/tests/data_types.ts @@ -301,3 +301,37 @@ testClient(async function jsonArray() { ], ); }); + +testClient(async function bool() { + const result = await CLIENT.query( + `SELECT bool('y')`, + ); + assertEquals(result.rows[0][0], true); +}); + +testClient(async function _bool() { + const result = await CLIENT.query( + `SELECT array[bool('y'), bool('n'), bool('1'), bool('0')]`, + ); + assertEquals(result.rows[0][0], [true, false, true, false]); +}); + +testClient(async function bytea() { + const result = await CLIENT.query( + `SELECT decode('MTIzAAE=','base64')`, + ); + assertEquals(result.rows[0][0], new Uint8Array([49, 50, 51, 0, 1])); +}); + +testClient(async function _bytea() { + const result = await CLIENT.query( + `SELECT array[ decode('MTIzAAE=','base64'), decode('MAZzBtf=', 'base64') ]`, + ); + assertEquals( + result.rows[0][0], + [ + new Uint8Array([49, 50, 51, 0, 1]), + new Uint8Array([48, 6, 115, 6, 215]), + ], + ); +});