728x90
반응형
1. Nestjs 프로젝트 생성
nest new typeorm2023
2. TypeORM 관련 패키지 설치
npm install --save @nestjs/typeorm typeorm mysql2
3. root 폴더에 orm.config.ts 추가 (수정필요)
import { TypeOrmModuleOptions } from "@nestjs/typeorm";
function ormConfig(): TypeOrmModuleOptions {
const commonConf = {
SYNCRONIZE: false,
ENTITIES: [__dirname + '/domain/*{.ts,.js}'],
MIGRATIONS: [__dirname + '/migrations/**/*{.ts,.js}'],
MIGRATIONS_RUN: false,
};
//
return {
name: 'default',
type: 'mysql',
database: 'test',
host: 'localhost',
port: Number(3306),
username: 'root',
password: 'root',
logging: true,
synchronize: commonConf.SYNCRONIZE,
entities: commonConf.ENTITIES,
migrations: commonConf.MIGRATIONS,
migrationsRun: commonConf.MIGRATIONS_RUN,
};
}
export { ormConfig };
4. app.module.ts에 ormConfig 추가
import { ormConfig } from './orm.config';
import { TypeOrmModule } from '@nestjs/typeorm';
@Module({
imports: [
TypeOrmModule.forRootAsync({ useFactory: ormConfig }),
...
],
...
})
반응형
'언어 > Nest.js' 카테고리의 다른 글
Nest.js Dockerize (0) | 2024.04.01 |
---|---|
Test Script (0) | 2024.04.01 |
DTO & Pipe (0) | 2024.04.01 |
Service & Entity (0) | 2024.04.01 |
Controller (0) | 2024.04.01 |