How to add logging for sequelize update

徘徊边缘 提交于 2020-01-05 04:07:12

问题


In my project sequelize logging is disabled, but I want active logging in the exact query.

How can I do that?

TableModel.update(
    {counter: 0},
    {where: {
        id: itm.i
    }},
    ).then((res) =>{
        console.log('res',res);
    }).catch(e => {
        console.log('update error : ', e);
    });

I know how I can do it in findall query like this:

TableModel.findAll({where: {...}, logging: console.log})

but in the update, I can't find any solution.

sequelize version: 5.21


回答1:


I found solution.

that was so easy just adding logging:true in options.

TableModel.update(
    {counter: 0},
    {
        where: {
            id: itm.i
        },
        logging:true
    }
    ).then((res) =>{
        console.log('res',res);
    }).catch(e => {
        console.log('update error : ', e);
    });


来源:https://stackoverflow.com/questions/59481110/how-to-add-logging-for-sequelize-update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!