From fcb6488531d7651f116e692f124e3b4aaa6979f2 Mon Sep 17 00:00:00 2001 From: Gajus Kuizinas Date: Wed, 23 Oct 2019 04:46:44 +0100 Subject: [PATCH] fix: encode binary data See: * https://github.com/brianc/node-postgres/issues/980 * https://github.com/brianc/node-pg-native/issues/83 --- src/routines/executeQuery.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/routines/executeQuery.js b/src/routines/executeQuery.js index 68d54579..02570ede 100644 --- a/src/routines/executeQuery.js +++ b/src/routines/executeQuery.js @@ -121,10 +121,25 @@ export default async ( try { try { + let finalValues = actualQuery.values; + + if (connection.native && actualQuery.values) { + finalValues = []; + + for (const value of actualQuery.values) { + if (Buffer.isBuffer(value)) { + // $FlowFixMe + finalValues.push('\\x' + value.toString('hex')); + } else { + finalValues.push(value); + } + } + } + result = await executionRoutine( connection, actualQuery.sql, - actualQuery.values, + finalValues, executionContext, actualQuery );