- git pull origin main -> git branch 만들기 -> git checkout으로 branch 들어가기
- posts 테이블 만들기
터미널에
dbmate new create_posts_table
CREATE TABLE POSTS(
id INT NOT NULL AUT0_INCREMENT,
title VARCHAR(100) NOT NULL,
content VARCHAR(2000) NULL,
image_url VARCHAR(1000) NULL,
user_id INT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTMAP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
- app.js에 작성
app.post("/posts/create", async (req,res) => {
const {title, content, image, user_id} = req.body
await appDataSource.query(
`Insert INTO posts(
title,
content,
image,
user_id
) VALUES(?,?,?);
`,
[title, description, converImage]
);
res.status(201).json({message : "postCreated"})
});