Reputation: 405
Below code throw "TypeError: sequelize.transaction is not a function" Error
sequelize.transaction(transaction => {
myDb.myTable.findAll({attributes:['IMAGEPATH'],where:{ID : customerId}})
.then((result) => {
....
}).then((commitResult) =>{
//commit
}).catch((rollbackErr) =>{
//rollback
})
Upvotes: 5
Views: 5298
Reputation: 82136
It looks like you're trying to reference the transaction
function on the definition as opposed to the instance i.e.
const sequelize = require('sequelize');
sequelize.transaction(...); // doesn't exist
You need to create a sequelize instance and use the transaction
function on this
const Sequelize = require('sequelize');
const db = new Sequelize(...);
db.transaction(...); // works
See the docs.
Upvotes: 10