0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

Added static transaction method to base model (#13260)

no-issue

Writing code outside of Ghost which deals with the models is currently
done by passing the models which are needed to the external module,
rather than the instance of ghostBookshelf. This does not give us a way
to create transaction to run queries in. This method is designed as a
simple way to give all models the power to create a transaction for
themselves.

This will be used in @tryghost/members-api for example to ensure that
failures in communication with the Stripe API will rollback the related
inserts in the database.
This commit is contained in:
Fabien 'egg' O'Carroll 2021-08-26 20:01:42 +02:00 committed by GitHub
parent 9a1417c8b9
commit bee1d4793d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -63,6 +63,16 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
return true;
}
}, {
/**
* @template T
* @param {(transaction: import('knex').Transaction) => Promise<T>} fn
*
* @returns {Promise<T>}
*/
transaction(fn) {
return ghostBookshelf.transaction(fn);
}
});
// Export ghostBookshelf for use elsewhere