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.
Loopback data-juggler中是否有远程方法或任何其他环回组件,它将允许我记录由数据源执行的查询。
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 *来自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 . as suggested here https://groups.google.com/forum/#!topic/loopbackjs/rpii8R8iUkw
我尝试以DEBUG = loopback:connector:* node运行我的应用程序。正如此处所建议的那样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)
有没有更好的替代方案,我可以从数据源获得响应并根据我的要求进行调整? (就像显示是否使用了索引一样)
1 个解决方案
#1
-1
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();
});
#1
-1
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();
});