brianc / node-pg-copy-streams

COPY FROM / COPY TO for node-postgres. Stream from one database to another, and stuff.
331 stars 40 forks source link

COPY TO with query_timeout #156

Open boromisp opened 5 months ago

boromisp commented 5 months ago

Similarly to https://github.com/brianc/node-postgres/issues/3219, COPY TO doesn't play nice with query_timeout. https://github.com/brianc/node-pg-copy-streams/pull/126 fixed this issue for COPY FROM.

I've been using this patch for some time now, and it seems to work:

const { to: copyTo } = require('pg-copy-streams');

const fixedCopyTo = (query, options) => {
  const streamQuery = copyTo(query, options);

  streamQuery.callback = () => {};

  const handleError = streamQuery.handleError.bind(streamQuery);
  const handleReadyForQuery = streamQuery.handleReadyForQuery.bind(streamQuery);

  streamQuery.handleError = e => {
    streamQuery.callback();
    handleError(e);
  };

  streamQuery.handleReadyForQuery = () => {
    streamQuery.callback();
    handleReadyForQuery();
  };

  return streamQuery;
};

module.exports = fixedCopyTo;