TypeORM
- TypeORM 설치
- module 연결
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
@Module({
imports: [
TypeOrmModule.forRoot({
type: 'mysql',
host: 'localhost',
port: 3306,
username: 'root',
password: 'root',
database: 'test',
entities: [],
synchronize: true,
logging: true,
}),
],
})
export class AppModule {}
- entity 파일 생성
@Entity()
export class test {
@PrimaryGeneratedColum("option") // id값 생성 option : uuid - unique increment - 알아서 1씩 증가
number: number;
@Colum()
name: string;
@Colum()
address: string;
}
- TypeModule 에서 entities에 추가 필요
- nest.js 실행 시 자동으로 테이블 생성해줌