sequelize

const Sequelize = require('sequelize');
const sequelize = new Sequelize('DDT', 'sa', 'Sa123456', {
host: "106.15.231.234",
port: 1433,
dialect: 'mssql'
})
//;SELECT * FROM aAddress where aAddressId=2102
// sequelize.query('SELECT * FROM aAdmin where aAdminId=:status',
// { replacements: { status: 5 }, type: sequelize.QueryTypes.SELECT }).then((results, metadata) => {
// console.log(results,metadata)
// })

sequelize.transaction(function (t) {
// 在这里链接您的所有查询。 确保你返回他们。
return Promise.all([
sequelize.query('update aAdmin set aAdminIsDel=3 where aAdminId=1', { type: sequelize.QueryTypes.SELECT }),
sequelize.query('SELECT * FROM aAdmin where aAdminId=1', { type: sequelize.QueryTypes.SELECT }),
//sequelize.query('SELECT * FROM aAdmin where aAdminId=2'),
//sequelize.query('SELECT * FROM aAdmin where aAdminId=3')
]);
// return sequelize.query('SELECT * FROM aAdmin where aAdminId=5', { transaction: t }).then((myTableRows) => {
// console.log(1)
// })
}).then(function (result, j) {
console.log(result[1])

//console.log(result)
// 事务已被提交
// result 是 promise 链返回到事务回调的结果

}).catch(function (err) {
console.log(err)
// 事务已被回滚
// err 是拒绝 promise 链返回到事务回调的错误
});

你可能感兴趣的:(sequelize)