2022-08-17 19:48:20 +00:00
|
|
|
import { Provider } from '@nestjs/common';
|
2022-03-19 10:25:37 +00:00
|
|
|
import { ConfigurationService } from 'src/modules/config/config.service';
|
|
|
|
import { ConnectionOptions, createConnection } from 'typeorm';
|
2022-03-09 18:37:04 +00:00
|
|
|
|
2022-08-17 19:48:20 +00:00
|
|
|
export const databaseProviders: Provider<any>[] = [
|
2022-03-09 18:37:04 +00:00
|
|
|
{
|
|
|
|
provide: 'DATABASE_CONNECTION',
|
2022-03-19 10:25:37 +00:00
|
|
|
useFactory: async (config: ConfigurationService) => {
|
|
|
|
return await createConnection({
|
|
|
|
...config.get<ConnectionOptions>('database'),
|
|
|
|
});
|
|
|
|
},
|
|
|
|
inject: [ConfigurationService],
|
2022-03-09 18:37:04 +00:00
|
|
|
},
|
|
|
|
];
|