Is there any approach how to set a mysql transaction inside a single request action method? So we may be able to rollback transaction whenever error occurs.
Code example:
export async function saveDepartmentAction(request: Request, response: Response) {
// data
let data = request.body
// insert department data
const result = await getEntityManager().query(`
// Some department insert (parent data)
`, [ some department data ])
// add child data (department positions)
data.positions.forEach(async position => {
const add_position = await getEntityManager().query(`
// Some position insert (child data)
`, [ some department id and position id ])
});
response.send(data)
}
Hi,
Is there any approach how to set a mysql transaction inside a single request action method? So we may be able to rollback transaction whenever error occurs.
Code example:
I would like to achieved something like this https://github.com/mysqljs/mysql#transactions