修复 SQLite 钱包调账锁异常

This commit is contained in:
2026-07-22 15:03:06 +08:00
parent cd1996f281
commit 7ffc573d2e
2 changed files with 58 additions and 4 deletions

View File

@@ -259,10 +259,13 @@ export class WalletsService {
if (!lock || !manager.createQueryBuilder) {
return manager.findOne(StudentWallet, { where: { studentId } });
}
return manager.createQueryBuilder(StudentWallet, 'wallet')
.where('wallet.studentId = :studentId', { studentId })
.setLock('pessimistic_write')
.getOne();
let query = manager
.createQueryBuilder(StudentWallet, 'wallet')
.where('wallet.studentId = :studentId', { studentId });
if (['mysql', 'mariadb', 'postgres', 'cockroachdb'].includes(this.dataSource.options.type)) {
query = query.setLock('pessimistic_write');
}
return query.getOne();
};
let wallet = await find();
if (!wallet) {