(TypeORM) TypeORM - Getting Start

최건·2025년 5월 6일

참고 문서

  • https://typeorm.io/
  • 해당 글은 NestJS 프레임워크를 기반으로 설명합니다.
  • Database는 MySQL을 기준으로 합니다.

TypeORM 라이브러리 다운로드 및 기타 설정

  1. TypeORM + DB 드라이버 설치
npm install @nestjs/typeorm typeorm mysql2
  1. TypeORM 설정
// app.module.ts
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { User } from './user/user.entity';

@Module({
  imports: [
    TypeOrmModule.forRoot({
      type: 'postgres', // 또는 'mysql', 'sqlite' 등
      host: 'localhost',
      port: 5432,
      username: 'your_username',
      password: 'your_password',
      database: 'your_database',
      entities: [User], // 또는 path: [__dirname + '/**/*.entity{.ts,.js}']
      synchronize: true, // 개발용 옵션 (운영환경에서는 false)
    }),
    TypeOrmModule.forFeature([User]), // Repository 사용을 위한 Entity 등록
  ],
})
export class AppModule {}
profile
개발이 즐거운 백엔드 개발자

0개의 댓글