How can I see the SQL generated by Sequelize.js?

node.js, sequelize.js

Solution

You can pass a logging option when initializing sequelize, which can either be a function or console.log

var sequelize = new Sequelize('database', 'username', 'password', {
    logging: console.log
    logging: function (str) {
        // do your own logging
    }
});

You can also pass a logging option to .sync if you only want to view the table creation queries

sequelize.sync({ logging: console.log })

Problem

I want to see the SQL commands that are sent to the PostgreSQL server because I need to check if they are correct. In particular, I am interested in the table creation commands. For instance, ActiveRecord (Ruby) prints its SQL statements to standard output. Is this possible with Node.js/ActionHero.js and Sequelize.js as well?

Original source