如何查看Sequelize.js生成的SQL? [英] How can I see the SQL generated by Sequelize.js?

查看:988
本文介绍了如何查看Sequelize.js生成的SQL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想查看发送到PostgreSQL服务器的SQL命令,因为我需要检查它们是否正确.我特别对表创建命令感兴趣.

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.

例如,ActiveRecord(Ruby)将其SQL语句打印到标准输出. Node.js/ActionHero.js和Sequelize.js也可能吗?

For instance, ActiveRecord (Ruby) prints its SQL statements to standard output. Is this possible with Node.js/ActionHero.js and Sequelize.js as well?

推荐答案

在初始化sequelize时,您可以传递一个日志记录选项,它可以是函数或console.log

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
    }
});

如果您只想查看表创建查询,也可以将日志记录选项传递给.sync

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

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

这篇关于如何查看Sequelize.js生成的SQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆