1. 次のコードは、送金処理にトランザクションを使っておらず、途中でエラーが起きたときに残高が不整合になる危険があります。信頼性(一貫性)の観点から、もっとも重要な改善はどれでしょうか?
async function transfer(db, fromId, toId, amount) {
await db.execute(
'UPDATE accounts SET balance = balance - ? WHERE id = ?',
[amount, fromId]
);
await db.execute(
'UPDATE accounts SET balance = balance + ? WHERE id = ?',
[amount, toId]
);
}
async function transfer(db, fromId, toId, amount) {
await db.execute(
'UPDATE accounts SET balance = balance - ? WHERE id = ?',
[amount, fromId]
);
await db.execute(
'UPDATE accounts SET balance = balance + ? WHERE id = ?',
[amount, toId]
);
}