Reputation: 4101
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?
Upvotes: 162
Views: 176322
Reputation: 1036
You can also take advantage of Sequelize's use of the Debug module, by setting your environment, thus:
DEBUG=sequelize:sql*
before starting your app.
Upvotes: 35
Reputation: 1532
As stated in the log Error: Please note that find* was refactored and uses only one options object from now on.
. For the latest sequelize version (4) if you want to have the result for only one command:
User.findAll({where: {...}, logging: console.log})
Upvotes: 86
Reputation: 743
If you want to look at the sequelize for one command you can listen to it and attach a function to the print the sql.
Check out this example:
User.find(1).on('sql', console.log).then(function(user) {
// do whatever you want with the user here
Upvotes: 33
Reputation: 28788
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 })
Upvotes: 232