fork download
  1. let productsStream = fs.createReadStream('products.csv')
  2. productsStream
  3. .pipe(csv({ separator: ';' }))
  4. .on('data', (data) => {
  5. const {sku, ...attributes} = data;
  6.  
  7. (async () => {
  8. const db = await sqlite.open({
  9. filename: 'products.db',
  10. driver: sqlite3.Database
  11. })
  12.  
  13. const {productId} = await db.get('SELECT id AS productId FROM products WHERE sku = ?', sku);
  14.  
  15. console.log('CURRENT PARSING SKU:', sku);
  16.  
  17. for (let key in attributes) {
  18. if (attributes[key].length) {
  19.  
  20. const {attributeId} = await db.get('SELECT id AS attributeId FROM attributes WHERE name = ?', key),
  21. attributeValue = attributes[key];
  22.  
  23. try {
  24. const result = await db.run(
  25. 'INSERT INTO prod_attrs (product_id, attribute_id, value) VALUES (?, ?, ?)',
  26. [productId, `${attributeId}`, `${attributeValue}`]
  27. )
  28. } catch (e) {
  29. console.log('ERROR: ', e);
  30. fs.appendFileSync('error_logs.txt', `\n ${e}`);
  31. }
  32. }
  33. }
  34.  
  35. await db.close();
  36. })()
  37.  
  38. })
  39. .on('end', () => {
  40. console.log('finished');
  41.  
  42. const finish = Date.now();
  43. console.log(finish - start);
  44.  
  45. })
  46. .on('close', () => {
  47. console.log('destroyed')
  48. })
Runtime error #stdin #stdout #stderr 0.03s 16588KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
prog.js:1:5 ReferenceError: fs is not defined
Stack:
  @prog.js:1:5