1
votes

Is there a remote method in Loopback data-juggler or any other loopback component which will let me log the query that is executed by the datasource.

Eg: If i'm using MySQL connector, then when MODEL_NAME.findById() is called, i should be able to get

SELECT * from DATABASE_NAME.MODEL_TABLE where id = WHATEVER_ID

Similarly for MongoDB, it should return equivalent mongo query It'd be great if i am able to log query.explain() of mongo here itself

I've tried running my app as DEBUG=loopback:connector:* node . as suggested here https://groups.google.com/forum/#!topic/loopbackjs/rpii8R8iUkw

It helps, but i'm not able to understand if the query used mongo indexes or not.

Is there a better alternative where i can get response from the datasource and trim it to my requirements? (like just showing if index was used or not)

1

1 Answers

-2
votes

about query execute command, maybe you can see this document Connector hooks

in my application, I use after execute to log insert and delete method

return db.observe('after execute', function(ctx, next) {
  let sql = ctx.req.sql;
  let isInsert = _.startsWith(sql, 'INSERT INTO');
  let isDelete = _.startsWith(sql, 'DELETE FROM');

  // logic code

  return next();
});