1

I need to get the sql query generated by a findAll call, preferably synchronously (w/o promise). It's not for logging purpose and i don't want it for all queries, just for one specific query so setting a logger like this answer won't help.

How can this be done?

Community
  • 1
  • 1
Mohammad Jafar Mashhadi
  • 4,102
  • 3
  • 29
  • 49

1 Answers1

2

You can set a specific log function to a single query. You probably can do whatever you need in it synchronously.

try something like:

//sample log function
function notOnlyALogger(msg){
   console.log('hey, Im a single log');
   //do whatever you need in here
   console.log(msg);
}

//using the logger only when needed
MyModel.findall({where:{foo:'bar'}, logging: notOnlyALogger });

and you should be fine.