mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-10 07:07:23 +00:00
23 lines
726 B
TypeScript
23 lines
726 B
TypeScript
import { NestFactory } from '@nestjs/core';
|
|
import { DataSource } from 'typeorm';
|
|
import { initializeTransactionalContext } from 'typeorm-transactional';
|
|
import { AppModule } from './src/app.module';
|
|
|
|
/**
|
|
* Getting data source through NestJS app helps in getting entities dynamically with "autoLoadEntities" NestJS feature
|
|
* as well as keeping migrations config in sync with what is configured in the app.
|
|
*/
|
|
async function getTypeOrmDataSource() {
|
|
process.env.MIGRATIONS_RUN = 'false';
|
|
initializeTransactionalContext();
|
|
|
|
const app = await NestFactory.createApplicationContext(AppModule);
|
|
|
|
const dataSource = app.get(DataSource);
|
|
await app.close();
|
|
|
|
return dataSource;
|
|
}
|
|
|
|
export default getTypeOrmDataSource();
|