Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get raw query generated by sequelize.js [duplicate]

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?

like image 807
Diego Moreira Avatar asked Feb 11 '23 04:02

Diego Moreira


1 Answers

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
  }
});
like image 120
Yuri Zarubin Avatar answered Feb 16 '23 12:02

Yuri Zarubin