data duplicator works in simple case

This commit is contained in:
Jan Prochazka
2023-02-11 10:17:10 +01:00
parent f3dd187df7
commit b5e37053b8
17 changed files with 517 additions and 61 deletions

View File

@@ -0,0 +1,41 @@
import _intersection from 'lodash/intersection';
import _isArray from 'lodash/isArray';
import { getLogger } from './getLogger';
const logger = getLogger('asyncWriteStream');
export interface AsyncWriteStreamOptions {
processItem: (chunk: any) => Promise<void>;
}
export function createAsyncWriteStream(stream, options: AsyncWriteStreamOptions): any {
const writable = new stream.Writable({
objectMode: true,
});
writable._write = async (chunk, encoding, callback) => {
await options.processItem(chunk);
// const { sql, id, newIdSql } = chunk;
// if (_isArray(sql)) {
// for (const item of sql) await driver.query(pool, item, { discardResult: true });
// } else {
// await driver.query(pool, sql, { discardResult: true });
// }
// if (newIdSql) {
// const res = await driver.query(pool, newIdSql);
// const resId = Object.entries(res?.rows?.[0])?.[0]?.[1];
// if (options?.mapResultId) {
// options?.mapResultId(id, resId as string);
// }
// }
callback();
};
// writable._final = async callback => {
// callback();
// };
return writable;
}