如何查看 Sequelize.js 生成的 SQL?

编程入门 行业动态 更新时间:2024-10-28 02:35:10
本文介绍了如何查看 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?

本文发布于:2023-10-23 08:14:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1520287.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Sequelize   js   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!