Skip to content

Commit

Permalink
feat: deprecate BulkLoad.addRow and BulkLoad.getRowStream
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurschreiber authored Sep 28, 2021
1 parent 181cd15 commit 91c7701
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/bulk-load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@ class BulkLoad extends EventEmitter {
addRow(row: unknown[]): void

addRow(...input: [ { [key: string]: unknown } ] | unknown[]) {
emitAddRowDeprecationWarning();

this.firstRowWritten = true;

let row: any;
Expand Down Expand Up @@ -695,6 +697,8 @@ class BulkLoad extends EventEmitter {
* stream or an `AsyncGenerator`) when calling [[Connection.execBulkLoad]]. This method will be removed in the future.
*/
getRowStream() {
emitGetRowStreamDeprecationWarning();

if (this.firstRowWritten) {
throw new Error('BulkLoad cannot be switched to streaming mode after first row has been written using addRow().');
}
Expand All @@ -720,5 +724,37 @@ class BulkLoad extends EventEmitter {
}
}

let addRowDeprecationWarningEmitted = false;
function emitAddRowDeprecationWarning() {
if (addRowDeprecationWarningEmitted) {
return;
}

addRowDeprecationWarningEmitted = true;

process.emitWarning(
'The BulkLoad.addRow method is deprecated. Please provide the row data for ' +
'the bulk load as the second argument to Connection.execBulkLoad instead.',
'DeprecationWarning',
BulkLoad.prototype.addRow
);
}

let getRowStreamDeprecationWarningEmitted = false;
function emitGetRowStreamDeprecationWarning() {
if (getRowStreamDeprecationWarningEmitted) {
return;
}

getRowStreamDeprecationWarningEmitted = true;

process.emitWarning(
'The BulkLoad.getRowStream method is deprecated. You can pass an Iterable, AsyncIterable or ' +
'stream.Readable object containing the row data as a second argument to Connection.execBulkLoad instead.',
'DeprecationWarning',
BulkLoad.prototype.getRowStream
);
}

export default BulkLoad;
module.exports = BulkLoad;

0 comments on commit 91c7701

Please sign in to comment.