Diego Moreira Diego Moreira - 5 months ago 68
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

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