Im trying to extend the QueryBuilder
of Knex.js. I want to modify the delete()
method in order to delete the child elements of my Objection.js Model. Current code works well, but I want to support transactions in the new method:
class CustomQueryBuilder extends QueryBuilder {
// Override delete method
delete() {
return super.select('*').first().runAfter(async (old, builder) => {
// Some extra logic here, being able to access old entry
return await old.query().nativeDelete() // original delete
})
}
nativeDelete() {
return super.delete()
}
}
Where is the transaction of current context? Is it accesible?
Note: I cannot pass it as a param in delete(trx)
function, since delete()
could be called from other methods without passing it explicitly as a param