nestjs / typeorm

TypeORM module for Nest framework (node.js) 🍇

Home Page:https://nestjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@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!';
  }
}
  1. Nest does not strive to be "like Java".

  2. Please use our Discord channel (Support). We are using GitHub to track Bug Reports, Feature Requests, and Regressions.