@Transaction()Implementing data consistency
kuangshp opened this issue · comments
How can decorators be used directly to achieve data consistency in NestJS, like things in Java
@Injectable()
export class AppService {
constructor(
@InjectRepository(RoleEntity)
private readonly roleRepository: Repository<RoleEntity>,
@InjectRepository(AccountEntity)
private readonly accountRepository: Repository<AccountEntity>,
) {}
@Transaction()
async getHello(): Promise<string> {
const account = this.accountRepository.create({ username: 'admin' });
await this.accountRepository.save(account);
const obj: any = { name: 'hello' };
console.log(obj.age.a);
const role = this.roleRepository.create({ name: 'role' });
await this.roleRepository.save(role);
return 'success!';
}
}
-
Nest does not strive to be "like Java".
-
Please use our Discord channel (Support). We are using GitHub to track Bug Reports, Feature Requests, and Regressions.