Skip to content

COPY TO with query_timeout #156

@boromisp

Description

@boromisp

Similarly to brianc/node-postgres#3219, COPY TO doesn't play nice with query_timeout. #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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions