#Dynamic TypeOrmModule name

12 messages · Page 1 of 1 (latest)

wicked cave
#

Hi ! Is there a way to use a dynamic name based on the request for the TypeOrmModule when using useFactory ?

Reference : https://docs.nestjs.com/techniques/database#multiple-databases

In the documentation and the type definition it don't seems to be possible..

dusk moss
#

Nope, nor does there really need to be. You only inject one connection at a time to your application, regardless of the connection's details, so having a single provider token for the connection is fine

wicked cave
dusk moss
#

The connection can be created from the request, for each request, but the injection token, what tells Nest what to inject and where, will be static. The value the token points to is dynamic, but the token itself is static

wicked cave
dusk moss
#

Usually, yes. It's recreated. There is the idea of durable providers which are request scoped and reused

wicked cave
dusk moss
#

Benchmark it and find the performance difference

wicked cave
dusk moss
#

Should be. That was one of the use cases in mind

wicked cave
#

Sorry to bother you with this, but do you have an example ? Even without typeorm. The one in the documentation doesn't help me to understand how to use a durable provider from a module defined in the "import" of a module. 😅

dusk moss
#

I don't but check the integration tests