本文介绍了获取sequelize.js生成的原始查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家下午好。我正在使用sequelize.js(postgresql)开发一个node.js / express系统。
Good afternoon everyone. I am developing a node.js/express system using sequelize.js (postgresql).
我的问题是:我需要将sequelize生成的原始查询存储在日志历史记录中,但是找不到返回所生成查询的函数。有谁知道sequelize是否提供了返回生成的SQL查询的函数,或者是否还有其他方法可以实现此目的?
My problem is: I need to store the raw queries generated by sequelize in a log history, but I can't find a function that returns the generated query. Does anyone know if sequelize provides a function that returns the generated SQL query, or if there's any other way to achieve this?
推荐答案
最好的选择是使用Sequelize的内置日志记录功能。
Your best bet is to use Sequelize's built-in logging functionality.
var sequelize = new Sequelize('db', 'username', 'pwd', {
// you can either write to console
logging: console.log
// or write your own custom logging function
logging: function (str) {
// do stuff with the sql str
}
});
这篇关于获取sequelize.js生成的原始查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!