unify streams

This commit is contained in:
Simon Martín 2018-06-21 14:53:07 +02:00
parent f4651cadae
commit 3ede1ea9f1

View File

@ -12,8 +12,7 @@ module.exports = class StreamCopy {
this.sql = sql; this.sql = sql;
this.connectionClosedByClient = false; this.connectionClosedByClient = false;
this.copyToStream = null; this.stream = null;
this.copyFromStream = null;
} }
static get ACTION_TO() { static get ACTION_TO() {
@ -30,8 +29,8 @@ module.exports = class StreamCopy {
return cb(err); return cb(err);
} }
this.copyToStream = copyTo(this.sql); this.stream = copyTo(this.sql);
const pgstream = client.query(this.copyToStream); const pgstream = client.query(this.stream);
pgstream pgstream
.on('end', () => done()) .on('end', () => done())
@ -55,8 +54,8 @@ module.exports = class StreamCopy {
return cb(err); return cb(err);
} }
this.copyFromStream = copyFrom(this.sql); this.stream = copyFrom(this.sql);
const pgstream = client.query(this.copyFromStream); const pgstream = client.query(this.stream);
pgstream pgstream
.on('end', () => done()) .on('end', () => done())
@ -69,13 +68,7 @@ module.exports = class StreamCopy {
}); });
} }
getRowCount(action = ACTION_TO) { getRowCount() {
if (action === ACTION_TO && this.copyToStream) { return this.stream.rowCount;
return this.copyToStream.rowCount;
}
if (action === ACTION_FROM && this.copyFromStream) {
return this.copyFromStream.rowCount;
}
} }
}; };