@nestjs/typeorm
[email protected]
pg
npm install pg [email protected] @nestjs/typeorm --save
typeorm은 0.3.0 이상 버전에서 Repository 를 사용할 수가 없고 커스텀 레포지토리를 사용해야 한다.
0.2 버전으로 설치할 것
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
export const typeORMConfig: TypeOrmModuleOptions = {
type: 'postgres',
host: 'localhost',
port: 5432,
username: 'postgres',
password: 'postgres',
database: 'board-app',
entities: [__dirname + '/../**/*.entity.{js,ts}'],
synchronize: true,
};
@Module({
imports: [typeORMConfig.forRoot(typeORMConfig), BoardsModule],
controllers: [],
providers: [],
})
export class AppModule {}
import { BaseEntity, Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
import { BoardStatus } from './board.model';
@Entity()
export class Board extends BaseEntity {
@PrimaryGeneratedColumn()
id: number;
@Column()
title: string;
@Column()
description: string;
@Column()
status: BoardStatus;
}