Search code examples
javascriptmysqlloggingsequelize.js

How to add logging for sequelize update


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


Solution

  • I found the solution.

    Was so easy, you need to just add logging:true in the sequelize options.

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