Diego Moreira Diego Moreira - 1 year ago 250
Node.js Question

Get raw query generated by sequelize.js

Good afternoon everyone. I am developing a node.js/express system using sequelize.js (postgresql).

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?

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download