Answer the question
In order to leave comments, you need to log in
Why is the rest of the code not executed after the function call?
There is a module for working with transactions in mysql:
exports.prepareTransaction = () => {
return new Promise((resolve, reject) => {
pool.getConnection((err, connection) => {
if (err) throw err;
const query = promisify(connection.query).bind(connection);
const commit = promisify(connection.commit).bind(connection);
const rollback = promisify(connection.rollback).bind(connection);
const beginTransaction = promisify(connection.beginTransaction).bind(connection);
const release = promisify(connection.release).bind(connection);
resolve({beginTransaction, query, commit, rollback, release});
});
});
};
let transaction = await connection.prepareTransaction();
try {
await transaction.beginTransaction();
...
await transaction.commit();
await transaction.release();
// дальше код не выполняется никакой
}
Answer the question
In order to leave comments, you need to log in
Apparently the promise transaction.release()
never becomes fullfilled, so the await doesn't complete.
Try rewriting it as a Promise and see if anything gets executed in the then or catch block.
let transaction = await connection.prepareTransaction();
try {
await transaction.beginTransaction();
...
await transaction.commit();
transaction.release()
.then(res=>{
console.log(res);
})
.catch(err=>{
console.error(err);
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question