1. SQL ๊ธฐ๋ณธ๊ธฐ
1-- select {column} from {table}2select id, author, title, content3from post;45-- update {table} set {column} where {condition}6update post set likeCount = 07where id =3;89-- delete from {table} where {condition}10delete from post11where author = 'newjeans_official';1213-- insert into {table} {column1, column2, ...}14-- values {value1, value2, ...}15insert into posts (id, author, title)16values (7, '๋๋ค', '์ ๋ชฉ');
2. Docker ์ด๋ก
๊ฐ๋ฐ์๋ค์ด ๊ฐ์ง ์ปดํจํฐ, OS๊ฐ ๋ค ๋ค๋ฅด๊ธฐ ๋๋ฌธ์, ํ๊ฒฝ์ ๋ฐ๋ผ ์ฝ๋๊ฐ ์คํ์ด ๋ ์๋ ์๋ ์๋ ์์๋ค.
Windows, macOS, Linux ๋ฑ์ ํ๊ฒฝ๋ค์ ์๋ก ํธํ๋๊ฒ ํ๊ธฐ ์ํด์ ๊ณผ๊ฑฐ๋ถํฐ ๋ง์ ์๋๋ค์ด ์์๋ค. ๋ ์ค์น ๊ฐ์ด๋ ์ญ์ ํ์คํํ์ฌ OS๊ฐ ๋ฌ๋ผ๋ ๊ฐ์ ๊ฒฐ๊ณผ๋ฅผ ์คํํ ์ ์๊ฒ ํ๋ค.
4. Docker ์ค์น
5. Docker-Compose
docker-compose.yaml
1# ์๋น์ค์ ์2services:3postgres:4image: postgres:155# ์คํ์๋ง๋ค ์ฌ์์6restart: always7# ๋์ปค์ปดํฌ์ฆ ํ์ผ์ ์กด์ฌํ๋ ์์น์ ์ค์ ๋ฐ์ดํฐ๋ฅผ hostOS์ ์ ์ฅ8volumes:9# ํ์ฌ ๋์ปค์ปดํฌ์ฆ ํ์ผ์ด ์กด์ฌํ๋ ๊ฒฝ๋ก : ์ด๋ฏธ์ง์์์กด์ฌํ๋ ๊ฒฝ๋ก ๋งคํ10- ./postgres-data:/var/lib/postgresql/data11ports:12# hostport:์ด๋ฏธ์ง์ํฌํธ13# 5432ํฌํธ ์์ฒญ -> ์ด๋ฏธ์ง์ ํฌํธ๋ก ์์ณฅ14- '5808:5432'15environment:16POSTGRES_USER: postgres17POSTGRES_PASSWORD: postgres18POSTGRES_DB: postgres
postgres-data ํด๋๋ฅผ ๋ง๋ ๋ค์, ์๋ ๋ช ๋ น์ด๋ก docker๋ฅผ ์ผญ๋๋ค.
1docker-compose up
6. VSC์์ Postersql ํ์ฅ๋๊ตฌ
vscode์์ ์คํ์ฐฝ(cmd + p)๋ก postgresql:add Connection ๊ฒ์
- 127.0.0.1
- postgres (ํ๊ฒฝ์ค์ ์ ์ ๋ ฅํ ์ ์ ๋ช )
- postgres (ํ๊ฒฝ์ค์ ์ ์ ๋ ฅํ ๋น๋ฐ๋ฒํธ)
- 5432
- standard connection
- ํฌํธ๋ฒํธ๋ฅผ ์ ์ค์ ํด์ ๊ทธ๋ฅ enter
- nestjs_local_database (์ฐ๊ฒฐ ์ด๋ฆ๋ช ์ค์ )
์์ผ๋ก ์ค์ตํ๋ ค๋ฉด
- docker ํ๋ก๊ทธ๋จ ์ผ๊ณ ,
- docker-compose ์ด๋ฏธ์ง๋ฅผ ์คํ(
docker-compose up)- nestjs ํ๋ก๊ทธ๋จ ์คํ