Hook(x) with Power.
Install it with npm first.
$ npm install hookx --save
Require it first.
const { hook, before, after } = require('hookx');
You should have an async function defined like this:
var query = async function (sql) {
// TODO
};
Hook it with before
and after
business logic.
var query = hook(query, async function (sql) {
console.time(sql);
}, async function (sql) {
console.timeEnd(sql);
});
await query(sql); // call the hooked async function like origin
Hook with before
business logic.
var counter = 0;
var query = before(query, async function (sql) {
counter++;
});
await query(sql);
Hook with after
business logic.
var counter = 0;
var query = after(query, async function (sql) {
counter--;
});
await query(sql);
The MIT license.