Skip to content

Instantly share code, notes, and snippets.

@FbN
Created April 11, 2023 09:13
Show Gist options
  • Save FbN/e0c8f14f95322473ca75c86ebf1b171f to your computer and use it in GitHub Desktop.
Save FbN/e0c8f14f95322473ca75c86ebf1b171f to your computer and use it in GitHub Desktop.
knex async modify
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