未处理的拒绝SequelizeDatabaseError - 流csv更新数据库

时间:2018-03-15 00:30:59

标签: csv express sequelize.js

我在s3存储桶中有几百个csv个文件。我正在构建服务器,将获取这些csv文件并使用Sequelize更新我的数据库。

我作为调度程序运行此任务,我偶尔会看到这些错误。它不会一直发生,所以我怀疑它与Promises有关。

以下是代码:

FilesNames包含文件名列表。然后,我使用csvtojson从流中读取这些csv,并使用Sequlize

插入这些数据
fileNames.forEach(file => {
      const csvFilePath = `${new_url}${file}`;
      csv({
        noheader: true,
      })
        .fromStream(request.get(csvFilePath))
        .on('csv', (csvRow, rowIndex) => {
          Hydrograph.create({
            data: csvRow,
            gaugeId: Number(file.slice(10, -4)),
            percentille: PERCENTILLE[rowIndex],
            type: 'GAUGE',
          });
        });
    });

这些是我得到的错误。这些错误有时只会出现。

  

未处理拒绝SequelizeDatabaseError:类型为numeric的输入语法无效:“”       在Query.formatError(/Users/leoqiu/apps/eflow-api/node_modules/sequelize/lib/dialects/postgres/query.js:363:16)       在query.catch.err(/Users/leoqiu/apps/eflow-api/node_modules/sequelize/lib/dialects/postgres/query.js:86:18)       在tryCatcher(/Users/leoqiu/apps/eflow-api/node_modules/bluebird/js/release/util.js:16:23)       在Promise._settlePromiseFromHandler(/Users/leoqiu/apps/eflow-api/node_modules/bluebird/js/release/promise.js:512:31)       在Promise._settlePromise(/Users/leoqiu/apps/eflow-api/node_modules/bluebird/js/release/promise.js:569:18)       在Promise._settlePromise0(/Users/leoqiu/apps/eflow-api/node_modules/bluebird/js/release/promise.js:614:10)       在Promise._settlePromises(/Users/leoqiu/apps/eflow-api/node_modules/bluebird/js/release/promise.js:689:18)       at Async._drainQueue(/Users/leoqiu/apps/eflow-api/node_modules/bluebird/js/release/async.js:133:16)       at Async._drainQueues(/Users/leoqiu/apps/eflow-api/node_modules/bluebird/js/release/async.js:143:10)       在Immediate.Async.drainQueues(/Users/leoqiu/apps/eflow-api/node_modules/bluebird/js/release/async.js:17:14)       在runCallback(timers.js:781:20)       在tryOnImmediate(timers.js:743:5)       at processImmediate [as _immediateCallback](timers.js:714:5)

0 个答案:

没有答案