Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function import_csv(fileName, modelName) {
- const errFile = fs.createWriteStream('csv/err/'+fileName+'.json');
- fs.createReadStream('csv/'+fileName)
- .pipe(iconv.decodeStream('win1252'))
- .pipe(csv({ separator: ';' }))
- .pipe(pressure(function (data, cb) {
- const row = Object.keys(data).reduce((acc, key) => {
- const newKey = key.replace(/-/g, '_');
- const newData = data[key].length ? data[key] : null;
- return { ...acc, [newKey]: newData };
- }, {});
- db[modelName].create(row)
- .then(() => cb())
- .catch(function (err) {
- row.errors = err.errors;
- JSON.stringify(row).pipe(errFile);
- });
- }, concurrency));
- }
Add Comment
Please, Sign In to add comment