sequelize.query()引发未处理的拒绝

时间:2019-06-10 07:15:01

标签: javascript sequelize.js

我得到

error: Unhandled Rejection at: Promise {"_bitField":18087936,"_fulfillmentHandler0":{}}

var Query = [
          `SELECT COUNT(*) FROM ${table1};`,
          `SELECT COUNT(*) FROM ${table2};`
        ];
sequelize.query(Query).then(result => {
          console.log(result);
        });

什么原因导致此错误?

2 个答案:

答案 0 :(得分:0)

在处理承诺时始终使用catch块。

      `sequelize.query(Query).then(result => {
      console.log(result);
    }).catch(error =>  console.log(error));`

答案 1 :(得分:0)

在创建连接时必须设置multipleStatements = true:

new Sequelize(..., {
  dialectOptions: {
    multipleStatements: true
  }
})