bellboy 8.6.0 → 8.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -207,9 +207,12 @@ job.on("loadingBatch", async (destinationIndex: number, data: any[]) => {
207
207
  ```
208
208
 
209
209
  ```ts
210
- job.on("loadedBatch", async (destinationIndex: number, data: any[]) => {
211
- // Batch has been loaded into destination.
212
- });
210
+ job.on(
211
+ "loadedBatch",
212
+ async (destinationIndex: number, data: any[], result: any) => {
213
+ // Batch has been loaded into destination.
214
+ }
215
+ );
213
216
  ```
214
217
 
215
218
  ```ts
@@ -715,7 +718,9 @@ Inserts data to MySQL.
715
718
  - **host**
716
719
  - **database**
717
720
  - **useSourceColumns** `boolean` \
718
- If `true`, only the columns in the source data will be used for data load. Default is `false`, using all destination table columns.
721
+ If `true`, only the columns in the source data will be used for data load. Default is `false`, using all destination table columns.
722
+ - **postLoadQuery** `string` \
723
+ A query which will be executed after the data load and before connection is closed. Result will be available in the `result` object of the `loadedBatch` event.
719
724
 
720
725
  ### MssqlDestination <div id='mssql-destination'/>
721
726
 
@@ -3,6 +3,7 @@ import { DatabaseDestination } from './base/database-destination';
3
3
  export declare class MySqlDestination extends DatabaseDestination {
4
4
  protected connection: IMySqlDbConnection;
5
5
  protected useSourceColumns: boolean;
6
+ protected postLoadQuery?: string;
6
7
  constructor(config: IMySqlDestinationConfig);
7
- loadBatch(data: any[]): Promise<void>;
8
+ loadBatch(data: any[]): Promise<any>;
8
9
  }
@@ -7,10 +7,12 @@ const promise_1 = tslib_1.__importDefault(require("mysql2-stream-fix/promise"));
7
7
  class MySqlDestination extends database_destination_1.DatabaseDestination {
8
8
  connection;
9
9
  useSourceColumns;
10
+ postLoadQuery;
10
11
  constructor(config) {
11
12
  super(config);
12
13
  this.connection = config.connection;
13
14
  this.useSourceColumns = config.useSourceColumns || false;
15
+ this.postLoadQuery = config.postLoadQuery;
14
16
  }
15
17
  async loadBatch(data) {
16
18
  const pool = promise_1.default.createPool(this.connection);
@@ -30,7 +32,7 @@ class MySqlDestination extends database_destination_1.DatabaseDestination {
30
32
  const insertQuery = `INSERT INTO ${this.table} (${columnNames.join(', ')}) VALUES ?`;
31
33
  await dbConnection.beginTransaction();
32
34
  try {
33
- const insertData = data.map(row => columnNames.map(column => row[column.replace(/`/g, '')] || null));
35
+ const insertData = data.map(row => columnNames.map(column => row[column.replace(/`/g, '')]));
34
36
  await dbConnection.query(insertQuery, [insertData]);
35
37
  await dbConnection.commit();
36
38
  }
@@ -39,7 +41,19 @@ class MySqlDestination extends database_destination_1.DatabaseDestination {
39
41
  throw err;
40
42
  }
41
43
  finally {
42
- await pool.end();
44
+ let result;
45
+ try {
46
+ if (this.postLoadQuery) {
47
+ result = await dbConnection.query(this.postLoadQuery);
48
+ }
49
+ }
50
+ catch (postLoadError) {
51
+ throw postLoadError;
52
+ }
53
+ finally {
54
+ await pool.end();
55
+ }
56
+ return result;
43
57
  }
44
58
  }
45
59
  }
package/lib/job.d.ts CHANGED
@@ -21,7 +21,7 @@ export declare class Job implements IJob {
21
21
  stop(message?: string): void;
22
22
  run(): Promise<void>;
23
23
  on(eventName: 'endProcessing', event?: (() => Promise<any>), extendedEvent?: extendedEvent): any;
24
- on(eventName: 'loadedBatch', event?: ((destinationIndex: number, data: any[]) => Promise<any>), extendedEvent?: extendedEvent): any;
24
+ on(eventName: 'loadedBatch', event?: ((destinationIndex: number, data: any[], result?: any) => Promise<any>), extendedEvent?: extendedEvent): any;
25
25
  on(eventName: 'processingError', event?: ((error: any) => Promise<any>), extendedEvent?: extendedEvent): any;
26
26
  on(eventName: 'loadingBatchError', event?: ((destinationIndex: number, data: any[], error: any) => Promise<any>), extendedEvent?: extendedEvent): any;
27
27
  on(eventName: 'loadingBatch', event?: ((destinationIndex: number, data: any[]) => Promise<any>), extendedEvent?: extendedEvent): any;
package/lib/job.js CHANGED
@@ -153,8 +153,8 @@ class Job {
153
153
  await this.emit('loadingBatch', destinationIndex, data);
154
154
  if (!this.stopped) {
155
155
  try {
156
- await destination.loadBatch(data);
157
- await this.emit('loadedBatch', destinationIndex, data);
156
+ const result = await destination.loadBatch(data);
157
+ result ? await this.emit('loadedBatch', destinationIndex, data, result) : await this.emit('loadedBatch', destinationIndex, data);
158
158
  }
159
159
  catch (err) {
160
160
  await this.emit('loadingBatchError', destinationIndex, data, err);
package/lib/types.d.ts CHANGED
@@ -79,7 +79,7 @@ export interface IProcessor {
79
79
  rowLimit: number;
80
80
  }
81
81
  export interface IDestination {
82
- loadBatch: (data: any[]) => Promise<void>;
82
+ loadBatch: (data: any[]) => Promise<any>;
83
83
  batchSize: number;
84
84
  recordGenerator: ((row: any) => AsyncIterableIterator<{}>) | undefined;
85
85
  batchTransformer: ((rows: any[]) => Promise<any[]>) | undefined;
@@ -104,6 +104,7 @@ export interface IMssqlDestinationConfig extends IDatabaseDestinationConfig {
104
104
  export interface IMySqlDestinationConfig extends IDatabaseDestinationConfig {
105
105
  connection: IMssqlDbConnection;
106
106
  useSourceColumns?: boolean;
107
+ postLoadQuery?: string;
107
108
  }
108
109
  export interface IHttpDestinationConfig extends IDestinationConfig {
109
110
  request: AxiosRequestConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bellboy",
3
- "version": "8.6.0",
3
+ "version": "8.7.0",
4
4
  "description": "Highly performant JavaScript data stream ETL engine.",
5
5
  "main": "lib/index",
6
6
  "types": "lib/index",
@@ -43,7 +43,7 @@
43
43
  "aedes": "0.42.1",
44
44
  "body-parser": "1.20.3",
45
45
  "codecov": "3.8.3",
46
- "express": "4.21.0",
46
+ "express": "4.21.1",
47
47
  "jest": "29.7.0",
48
48
  "node-xlsx": "0.15.0",
49
49
  "ts-jest": "29.2.5",