Make KnexJS Transactions work with async/await

☆樱花仙子☆ 提交于 2019-12-02 05:59:16

Looks like you are creating transaction, but then you are not sending any queries to it, but send queries to the other database connections in knex's connection pool.

This is how you should use transactions with knex:

async () {
  try {
    const trxResult = await db.transaction(async (trx) => {
      const queryResult = await trx('table').where(... etc. ...);
      // do some more queries to trx
    });
    console.log("transaction was committed");
  } catch (e) {
    console.log("transaction was rolled back");
  }
}

Also you should try reduce amount of code to minimum before posting problems to stackoverflow. Hiding too much code to snippets doesn't help at all.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!