sequelize

作者: A根_53b1 | 来源:发表于2018-04-10 20:30 被阅读0次

    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

          本文链接:https://www.haomeiwen.com/subject/wzimhftx.html