본문 바로가기

Lecture

자바스크립트 postman 연결

1. npm install sequelize sequelize-cli mysql2

 

2. npx sequelize init (sequelize 폴더 생성)

 

3. config 폴더에서 config.json 수정

    >> password, database 이름 등

 

4. models 폴더안에 comment.js 파일 생성 (db모델 만드려고)

    >> 파일에서 db 모델 옵션 설정

 

예)

module.exports = (sequelize,DataTypes)=>{
    const Comment = sequelize.define('Comment',{
        userid:{
            type:DataTypes.STRING(30),
            allowNull:false,
        },
        content:{
            type:DataTypes.TEXT,
            allowNull:false,
        },
        date:{
            type:DataTypes.DATE,
            allowNull:false
        }
    },{
        charset:'utf8mb4', //mb4는 이모티콘도 됨
        collate:'utf8mb4_general_ci'
    })

    return Comment
}

 

 

5. models 폴더안에 index.js 파일 편집

 

    >> ls 날리고 comment 파일 불러온 후 인자값으로 sequelize,Sequelize넣어줌

    >> 예)

       

db.Comment = require('./comment')(sequelize,Sequelize);

'Lecture' 카테고리의 다른 글

NEXT 동적 라우팅 사용  (0) 2021.07.26
nginx 설치  (0) 2021.07.20
Restful API 매서드 타입  (0) 2021.07.19
EC2 웹 배포 npm 설치 오류  (0) 2021.07.19
웹 배포  (0) 2021.07.16