简体   繁体   English

环回:记录由数据源执行的查询

[英]loopback: logging queries executed by datasource

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 例如:如果我使用的是MySQL连接器,则在调用MODEL_NAME.findById()时,我应该能够

SELECT * from DATABASE_NAME.MODEL_TABLE where id = WHATEVER_ID SELECT * from DATABASE_NAME.MODEL_TABLE,其中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 同样对于MongoDB,它应该返回等效的mongo查询。如果我能够在此处自行记录mongo的query.explain(),那就太好了

I've tried running my app as DEBUG=loopback:connector:* node . 我尝试将我的应用程序运行为DEBUG = loopback:connector:* node。 as suggested here https://groups.google.com/forum/#!topic/loopbackjs/rpii8R8iUkw 如此处建议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. 它有帮助,但是我无法理解查询是否使用了mongo索引。

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) (就像只是显示是否使用索引)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM