Added concept of ghost-query debug mode

- Outputting all queries is too much debug info for normal dev
- Use DEBUG=ghost:*,ghost-query to debug queries
- Or just DEBUG=ghost-query
This commit is contained in:
Hannah Wolfe 2017-11-01 15:18:53 +00:00
parent 9b54ed0689
commit 5319fd4e35

View File

@ -1,4 +1,5 @@
var debug = require('ghost-ignition').debug('models:plugin:include-count'),
var _debug = require('ghost-ignition').debug._base,
debug = _debug('ghost-query'),
_ = require('lodash');
module.exports = function (Bookshelf) {
@ -61,7 +62,11 @@ module.exports = function (Bookshelf) {
fetch: function () {
this.addCounts.apply(this, arguments);
debug('QUERY', this.query().toQuery());
// Useful when debugging no. database queries, GQL, etc
// To output this, use DEBUG=ghost:*,ghost-query
if (_debug.enabled('ghost-query')) {
debug('QUERY', this.query().toQuery());
}
// Call parent fetch
return modelProto.fetch.apply(this, arguments);
@ -69,7 +74,11 @@ module.exports = function (Bookshelf) {
fetchAll: function () {
this.addCounts.apply(this, arguments);
debug('QUERY', this.query().toQuery());
// Useful when debugging no. database queries, GQL, etc
// To output this, use DEBUG=ghost:*,ghost-query
if (_debug.enabled('ghost-query')) {
debug('QUERY', this.query().toQuery());
}
// Call parent fetchAll
return modelProto.fetchAll.apply(this, arguments);