代码抛出“TypeError:sequelize.transaction不是函数”错误
sequelize.transaction(transaction => {
myDb.myTable.findAll({attributes:['IMAGEPATH'],where:{ID : customerId}})
.then((result) => {
....
}).then((commitResult) =>{
//commit
}).catch((rollbackErr) =>{
//rollback
})
答案 0 :(得分:2)
看起来您试图在定义上引用transaction
函数而不是实例,即
const sequelize = require('sequelize');
sequelize.transaction(...); // doesn't exist
您需要创建一个续集实例并使用此
上的transaction
函数
const Sequelize = require('sequelize');
const db = new Sequelize(...);
db.transaction(...); // works
请参阅docs。