Skip to Content
BackendNestJs06-SQL-Docker

1. SQL 기본기

sql
1
-- select {column} from {table}
2
select id, author, title, content
3
from post;
4
5
-- update {table} set {column} where {condition}
6
update post set likeCount = 0
7
where id =3;
8
9
-- delete from {table} where {condition}
10
delete from post
11
where author = 'newjeans_official';
12
13
-- insert into {table} {column1, column2, ...}
14
-- values {value1, value2, ...}
15
insert into posts (id, author, title)
16
values (7, '나다', '제목');

2. Docker 이론

개발자들이 가진 컴퓨터, OS가 다 다르기 때문에, 환경에 따라 코드가 실행이 될 수도 안 될 수도 있었다.

Windows, macOS, Linux 등의 환경들을 서로 호환되게 하기 위해서 과거부터 많은 시도들이 있었다. 또 설치 가이드 역시 표준화하여 OS가 달라도 같은 결과를 실행할 수 있게 한다.


4. Docker 설치


5. Docker-Compose

docker-compose.yaml
1
# 서비스정의
2
services:
3
postgres:
4
image: postgres:15
5
# 실행시마다 재시작
6
restart: always
7
# 도커컴포즈 파일에 존재하는 위치에 실제 데이터를 hostOS에 저장
8
volumes:
9
# 현재 도커컴포즈 파일이 존재하는 경로 : 이미지안에존재하는 경로 매핑
10
- ./postgres-data:/var/lib/postgresql/data
11
ports:
12
# hostport:이미지의포트
13
# 5432포트 요청 -> 이미지의 포트로 요쳥
14
- '5808:5432'
15
environment:
16
POSTGRES_USER: postgres
17
POSTGRES_PASSWORD: postgres
18
POSTGRES_DB: postgres

postgres-data 폴더를 만든 다음, 아래 명령어로 docker를 켭니다.

shellscript
1
docker-compose up

6. VSC에서 Postersql 확장도구

vscode에서 실행창(cmd + p)로 postgresql:add Connection 검색

  1. 127.0.0.1
  2. postgres (환경설정에 입력한 유저명)
  3. postgres (환경설정에 입력한 비밀번호)
  4. 5432
  5. standard connection
  6. 포트번호를 잘 설정해서 그냥 enter
  7. nestjs_local_database (연결 이름명 설정)

앞으로 실습하려면

  1. docker 프로그램 켜고,
  2. docker-compose 이미지를 실행(docker-compose up)
  3. nestjs 프로그램 실행