pg-copy-streams
Advanced tools
Comparing version 5.1.1 to 6.0.0
@@ -17,3 +17,5 @@ 'use strict' | ||
this.chunks = [] | ||
this.cb = null | ||
this.cb_CopyInResponse = null | ||
this.cb_ReadyForQuery = null | ||
this.cb_destroy = null | ||
this.cork() | ||
@@ -32,3 +34,3 @@ } | ||
} | ||
this.cb = cb | ||
this.cb_CopyInResponse = cb | ||
} | ||
@@ -41,8 +43,26 @@ | ||
} | ||
this.cb = cb | ||
this.cb_CopyInResponse = cb | ||
} | ||
_destroy(err, cb) { | ||
// writable.destroy([error]) was called. | ||
// send a CopyFail message that will rollback the COPY operation. | ||
// the cb will be called only after the ErrorResponse message is received | ||
// from the backend | ||
this.cb_destroy = cb | ||
const msg = err ? err.message : 'NODE-PG-COPY-STREAMS destroy() was called' | ||
const self = this | ||
const done = function () { | ||
self.connection.sendCopyFail(msg) | ||
} | ||
this.chunks = [] | ||
if (this._gotCopyInResponse) { | ||
return this.flush(done) | ||
} | ||
this.cb_CopyInResponse = done | ||
} | ||
_final(cb) { | ||
this.cb_ReadyForQuery = cb | ||
const self = this | ||
@@ -58,3 +78,3 @@ const done = function () { | ||
} | ||
this.cb = done | ||
this.cb_CopyInResponse = done | ||
} | ||
@@ -90,3 +110,10 @@ | ||
handleError(e) { | ||
this.emit('error', e) | ||
if (this.cb_destroy) { | ||
const cb = this.cb_destroy | ||
this.cb_destroy = null | ||
cb(e) | ||
} else { | ||
this.emit('error', e) | ||
} | ||
this.connection = null | ||
} | ||
@@ -96,5 +123,7 @@ | ||
this._gotCopyInResponse = true | ||
this.uncork() | ||
const cb = this.cb || function () {} | ||
this.cb = null | ||
if (!this.destroyed) { | ||
this.uncork() | ||
} | ||
const cb = this.cb_CopyInResponse || function () {} | ||
this.cb_CopyInResponse = null | ||
this.flush(cb) | ||
@@ -115,3 +144,8 @@ } | ||
// we delay the _final callback so that the 'finish' event is | ||
// sent only after the postgres connection is ready for a new query | ||
// sent only when the ingested data is visible inside postgres and | ||
// after the postgres connection is ready for a new query | ||
// Note: `pg` currently does not call this callback when the backend | ||
// sends an ErrorResponse message during the query (for example during | ||
// a CopyFail) | ||
this.cb_ReadyForQuery() | ||
@@ -118,0 +152,0 @@ this.connection = null |
{ | ||
"name": "pg-copy-streams", | ||
"version": "5.1.1", | ||
"version": "6.0.0", | ||
"description": "Low-Level COPY TO and COPY FROM streams for PostgreSQL in JavaScript using", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -59,2 +59,4 @@ ## pg-copy-streams | ||
In version 6.0.0+, If you have not yet finished ingesting data into a copyFrom stream and you want to ask postgresql to abort the process, you can call `destroy()` on the stream (or let `pipeline` do it for you if it detects an error in the pipeline). This will send a CopyFail message to the backend that will rollback the operation. Please take into account that this will not revert the operation if the CopyDone message has already been sent and is being processed by the backend. | ||
### duplex stream for replication / logical decoding scenarios (copyBoth - copy-both) | ||
@@ -131,2 +133,14 @@ | ||
### version 6.0.0 - published 2021-08-20 | ||
- Implement _destroy in COPY FROM operations. `pipeline` will automatically send a CopyFail message to the backend is a source triggers an error. cf #115 | ||
This version is a major change because some users of the library may have been using other techniques in order to ask the backend to rollback the current operation. | ||
### version 5.1.1 - published 2020-07-21 | ||
Bugfix release handling a corner case when an empty stream is piped into copy-from | ||
- fix copy-from.js handling of an empty source | ||
### version 5.1.0 - published 2020-06-07 | ||
@@ -133,0 +147,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34164
577
246