Created
April 11, 2023 09:13
-
-
Save FbN/e0c8f14f95322473ca75c86ebf1b171f to your computer and use it in GitHub Desktop.
knex async modify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const before = (target, f) => { | |
const then = target.then.bind(target) | |
target.then = (resolve, reject) => | |
f(target).then(() => then(resolve, reject), reject) | |
return target | |
} | |
Knex.QueryBuilder.extend('amodify', function (f) { | |
const q = this | |
const clone = this.clone.bind(this) | |
before(q, f) | |
this.clone = function () { | |
const cloned = clone() | |
before(cloned, f) | |
return cloned | |
} | |
return this | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment