fix: ensure decrypted PGP values are cast to text in SQL queries
- Added `::text` cast to `pgp_sym_decrypt` function calls for consistent data type handling.
This commit is contained in:
@@ -41,7 +41,9 @@ export const pgpEncrypted = customType<{ data: string; driverData: Buffer }>({
|
|||||||
export function withAutomaticPgpDecrypt<T extends AnyPgColumn>(column: T): T {
|
export function withAutomaticPgpDecrypt<T extends AnyPgColumn>(column: T): T {
|
||||||
const originalGetSQL = column.getSQL.bind(column);
|
const originalGetSQL = column.getSQL.bind(column);
|
||||||
column.getSQL = () =>
|
column.getSQL = () =>
|
||||||
sql`pgp_sym_decrypt(${originalGetSQL()}, ${getPgpKey()})`.mapWith(column);
|
sql`pgp_sym_decrypt(${originalGetSQL()}, ${getPgpKey()})::text`.mapWith(
|
||||||
|
column,
|
||||||
|
);
|
||||||
return column;
|
return column;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,5 +61,7 @@ export function pgpSymDecrypt(
|
|||||||
column: AnyPgColumn,
|
column: AnyPgColumn,
|
||||||
key: string | SQL,
|
key: string | SQL,
|
||||||
): SQL<string> {
|
): SQL<string> {
|
||||||
return sql`pgp_sym_decrypt(${column}, ${key})`.mapWith(column) as SQL<string>;
|
return sql`pgp_sym_decrypt(${column}, ${key})::text`.mapWith(
|
||||||
|
column,
|
||||||
|
) as SQL<string>;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user