feat: use getRepository instead of createEntityManager #156
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
first of all, thank you for porting the original repository to support later TypeORM versions.
My PR is a rather short one and I frankly don't know if my intended solution is too niche for the bigger picture on how general this library needs to be. But maybe I hope I can win you over. I have tapped into TypeORM only for about a week, so my judgement call might not well educated.
I am currently improving the test suite for a NodeJS project, trying to make the integration-testing developer experience as close to batteries included ecosystem like Python Django or Ruby on Rails, which was the reason why I came across your predecessor's library to support a factory_girl like pattern.
Besides adding a factory pattern to create test entities, I had also integrated this library to support isolating test cases inside their own transactions which can be rolled back after execution. The problem is, that now the
typeorm-factory
entities are created in different transaction contexts, because eachFactory.create(...)
creates a new EntityManager instance.The
typeorm-transactional
works by patching theDataSource.manager
andEntityManager.prototype.getRepository
(in contrast tocreateEntityManager
). After some consideration where to fix my issue, I came to the conclusion that I'd rather fix this issue on the factory side, because the factories operate on a higher level of the stack and there are probably good reasons not to patchcreateEntityManager
or even the underlyingEntityManagerFactory
to keep special use cases intact, where the manager creation is needed to for custom SQL queries.