You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need this feature as well. My current workaround (not an actual workaround) is to
constconfigService=newConfigService();// use the configService in DataSource creation
Moreover, if one uses the dataSourceFactory callback of type TypeOrmDataSourceFactory = (options?: DataSourceOptions) => Promise<DataSource>; there is the chance to create the DataSourceOptions here from the provided ConfigService in case of undefined.
Here is an example of a dataSourceFactory implementation outlining why this feature is urgently needed:
exportconstdataSourceFactory: TypeOrmDataSourceFactory=async(options?: DataSourceOptions,)=>{constconfigService=newConfigService();returnnewDataSource(options??{type: 'mysql',host: configService.get('HOST'),port: +configService.get('PORT'),username: configService.get('USERNAME'),password: configService.get('PASSWORD'),database: configService.get('DATABASE'),// and so on ...}).initialize();};
But we could also use provider to enhance DataSource creation in other ways. I create a pg-mem connection for instance when serving or unit testing my backends locally.
Is there an existing issue that is already proposing this?
Is your feature request related to a problem? Please describe it
I would like to provide my own DataSource, but I need to inject my
ConfigService
so that I can do things in myDataSource
depending on configuration.Describe the solution you'd like
The most straightforward solution is to provide a
dataSourceFactoryInject
option.A bigger change (which I think makes more sense) would be to remove
dataSourceFactory
and addwhich passes in the default provider, and the user can modify whatever they want, e.g.
Teachability, documentation, adoption, migration strategy
See solution.
What is the motivation / use case for changing the behavior?
See problem.
The text was updated successfully, but these errors were encountered: