A Transactional Method Decorator for TypeORM that uses Async Local Storage or cls-hooked to handle and propagate transactions between different repositories and service methods.
MIT License
201
stars
27
forks
source link
feat: allow to re-patch DataSource & Repository #23
In addition to using transactions or not, there's an opportunity to use a similar decorator pattern to switch between databases for read operations like @ReadReplica() for example.
In typeorm-transactional-cls-hooked, the patch process was called as patchTypeORMRepositoryWithBaseRepository(), so instead of calling it, we could use our own patch process that includes patches by the library.
However, typeorm-transactional does not work this way because the patching process is called in initializeTransactionalContext().
It may not be the best way, but we can avoid this by allowing defineProperty to be called again, and there seems no downside to do so.
In addition to using transactions or not, there's an opportunity to use a similar decorator pattern to switch between databases for read operations like
@ReadReplica()
for example.In
typeorm-transactional-cls-hooked
, the patch process was called aspatchTypeORMRepositoryWithBaseRepository()
, so instead of calling it, we could use our own patch process that includes patches by the library.However,
typeorm-transactional
does not work this way because the patching process is called ininitializeTransactionalContext()
.It may not be the best way, but we can avoid this by allowing
defineProperty
to be called again, and there seems no downside to do so.