W6D5 Sequelize

Jin Bae·2022년 12월 29일
0

스파르타코딩클럽

목록 보기
24/35

참고한 자료:
https://loy124.tistory.com/374

Sequelize

A ORM (Object Relational Mapper) to use MySQL. In contrast, mongoose is a ODM (Object Document Mapper) to use MongoDB.

  1. Install modules:
npm i sequelize mysql2 -S
npm i sequelize-cli -D
  1. Prepare to use sequelize:
npx sequelize init
  1. Edit config/config.json to my database information
  2. Create database
npx sequelize db:create

The files in the models folder saves data in a model form.
The files in the migrations folder is used to create and delete tables in the database.

  1. Create a table in the database
npx sequelize model:generate --name User --attributes email:string,nickname:string,password:string
npx sequelize model:generate --name Goods --attributes name:string,thumbnailUrl:string,category:string,price:decimal
npx sequelize model:generate --name Cart --attributes userId:integer,goodsId:integer,quantity:integer
  1. Make any changes to the files in the models and migrations folder, then migrate the tables.
npx sequelize db:migrate

To create or migrate DB in the test environment (in Windows):

npx sequelize db:create --env test
npx sequelize db:migrate --env test

수정할거:

  • 자료가 없으면 status 404

찾아볼거:

  • Service, controller
    클라이언트 - 컨트롤러 - 서비스 - 모델 - DB

요청 제한: 1. 클라이언트 throttle, debounce, 2. 서버 rate limit을 통해 요청의 횟수 제한

status 500

참조 무결성 제약조건

Secret key는 AWS ASM으로 관리

물어볼거:

  • Middleware에서 status 400을 호출하면 다음으로 넘어가는지
  • Are access and refresh token given at the same time at first

0개의 댓글