Commit/rollback a knex transaction using async/await

前端 未结 3 759
猫巷女王i
猫巷女王i 2021-01-03 00:27

I\'m test driving the ES7 async/await proposal using this module to emulate it. I\'m trying to make knex.js transactions play well with them, as a starting point.

Ex

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-03 01:21

    You might be able to achieve this with something similar to this

    function createTransaction() {
      return new Promise((resolve) => {
        return knex.transaction(resolve);
      });
    }
    
    async function() {
      const trx = await createTransaction();
      ...
      trx.commit();
    }
    

提交回复
热议问题