Files
zod-backend/typeorm.cli.ts
Abdalhamid Alhamad 970a41c895 feat: create junior
2024-12-09 13:11:18 +03:00

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();