Clean up copy-in internal API

This commit is contained in:
Brian M. Carlson 2013-10-22 00:23:43 -05:00
parent 1688567340
commit 99f9492c72
2 changed files with 8 additions and 7 deletions

View File

@ -107,22 +107,22 @@ Client.prototype.connect = function(callback) {
});
con.on('copyInResponse', function(msg) {
self.activeQuery.streamData(self.connection);
self.activeQuery.handleCopyInResponse(self.connection);
});
con.on('copyOutResponse', function(msg) {
if(self.activeQuery.stream === undefined) {
self.activeQuery._canceledDueToError =
new Error('No destination stream defined');
if(self.activeQuery.stream === undefined) {
self.activeQuery._canceledDueToError = new Error('No destination stream defined');
//canceling query requires creation of new connection
//look for postgres frontend/backend protocol
//TODO - this needs to die/be refactored
(new self.constructor({port: self.port, host: self.host}))
.cancel(self, self.activeQuery);
}
});
con.on('copyData', function (msg) {
self.activeQuery.handleCopyFromChunk(msg.chunk);
self.activeQuery.handleCopyData(msg, self.connection);
});
con.on('notification', function(msg) {

View File

@ -170,12 +170,13 @@ Query.prototype.prepare = function(connection) {
this._getRows(connection, this.rows);
};
Query.prototype.streamData = function (connection) {
Query.prototype.handleCopyInResponse = function (connection) {
if(this.stream) this.stream.startStreamingToConnection(connection);
else connection.sendCopyFail('No source stream defined');
};
Query.prototype.handleCopyFromChunk = function (chunk) {
Query.prototype.handleCopyData = function (msg, connection) {
var chunk = msg.chunk;
if(this.stream) {
this.stream.handleChunk(chunk);
}