[Nest JS ๋ก CRUD ๊ฒ์ํ ๋ง๋ค๊ธฐ] (13) PostgresSQL ์ค์นํ๊ธฐ & TypeORM ์ฐ๊ฒฐํ๊ธฐ
<๋ณธ ๋ธ๋ก๊ทธ๋ John Ahn ์ ์ ํ๋ธ๋ฅผ ์ฐธ๊ณ ํด์ ๊ณต๋ถํ๋ฉฐ ์์ฑํ์์ต๋๋ค :-)>
=> ๋ฐ๋ผํ๋ฉด์ ๋ฐฐ์ฐ๋ NestJS
๐งธ PostgresSQL ์ค์นํ๊ธฐ
: ๋ฐ์ดํฐ๋ฒ ์ด์ค
https://www.postgresql.org/download/windows/
๐ pgAdmin
: ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ๋ณด๋ ํด
https://www.pgadmin.org/download/
๐งธ TypeORM
: node.js ์์ ์คํ๋๊ณ TypeScript ๋ก ์์ฑ๋ ๊ฐ์ฒด ๊ด๊ณํ ๋งคํผ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
: ๋ชจ๋ธ์ ๊ธฐ๋ฐ์ผ๋ก ๋ฐ์ดํฐ๋ฒ ์ด์ค ํ ์ด๋ธ ์ฒด๊ณ๋ฅผ ์๋์ผ๋ก ์์ฑ
: ํ ์ด๋ธ ๊ฐ์ ๋งคํ (์ผ๋์ผ, ์ผ๋ ๋ค ๋ฐ ๋ค ๋๋ค) ๋ง๋ฆ
: ๊ฐ๋จํ CLI ๋ช ๋ น์ ์ ๊ณต
npm install pg typeorm @nestjs/typeorm --save
๐ ORM (Object Relational Mapping)
: ๊ฐ์ฒด์ ๊ด๊ณํ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ๋ฐ์ดํฐ๋ฅผ ์๋์ผ๋ก ๋ณํ ๋ฐ ์ฐ๊ฒฐํ๋ ์์
: ORM ์ ์ด์ฉํ ๊ฐ๋ฐ์ ๊ฐ์ฒด์ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ๋ณํ์ ์ ์ฐํ๊ฒ ์ฌ์ฉํจ
๐ TypeORM ์ฐ๊ฒฐํ๊ธฐ
1) typeORM ์ค์ ํ์ผ ์ค์
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
}