Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Transactional Decorator #6183

Closed
ale-vncs opened this issue Apr 28, 2024 · 1 comment · Fixed by #6143
Closed

feat: add Transactional Decorator #6183

ale-vncs opened this issue Apr 28, 2024 · 1 comment · Fixed by #6143
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@ale-vncs
Copy link

Is your feature request related to a problem? Please describe.
Hey, this is amazing ORM to NestJS and I am migrating from TypeOrm, but I am passing by a problem.

In TypeOrm have a lib typeorm-transactional that add a @Transactional, like a Spring Framework, to create transaction in database with decorator. And this do more easy work with transaction, e.g:

@Transactional()
public async saveUser(data: CreateUserDto) {
  const newUserEntity = new UserEntity(data)
  await this.repository.save(newUserEntity)

  await this.addRoles(newUserEntity)

  return new UserResponseDto(newUserEntity)
}

private async addRoles(user: UserEntity) {
  await this.roleService.addDefaultRole(user)
}

If any error occur inside saveUser method or RoleService, a rollback is executed, otherwise a commit is executed when saveUser finalize.

And don't need inject EntityManager and call em.begin() or em.transactional(). In addition, don't need checked if exist a transactional open because @Transactional() manage this. See Propagation and Isolation

Describe the solution you'd like
The same solution of Spring @Transactional that typeorm-transactional uses

Describe alternatives you've considered
Using AsyncLocalStorage of node to manage a context of mikro-orm and open a transaction like typeorm-transactional

Additional context
...

@ale-vncs ale-vncs added the enhancement New feature or request label Apr 28, 2024
@B4nan B4nan added good first issue Good for newcomers help wanted Extra attention is needed labels May 19, 2024
@B4nan
Copy link
Member

B4nan commented May 20, 2024

Here is one implementation that came in as a workaround for a different problem with the ORM itself:

#5585 (comment)

I'd say this could be a worthy addition to the core package, it's not really tied to the nest integration.

@B4nan B4nan transferred this issue from mikro-orm/nestjs Oct 23, 2024
@B4nan B4nan closed this as completed in babe4da Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants