Sails.js best practice in using transactions with promises (Postgres)
问题 I'm using sails 0.9.16 with Postgres and my question is: what is the best way to execute transaction using current API with promises? May be there is something better than: Model.query('BEGIN TRANSACTION', function (err) { if (err) { next(err); } else { Model .create(...) .(function (value) { return [value, RelatedModel.create(...).then(...)]; }) .fail(function (err) { Model.query('ROLLBACK'); next(err); }) .spread(function (...) { Model.query('COMMIT') next(...); }) } }) Thanks for help! 回答1