FrameWork
-
Sequelize - 실전활용(Update,Delete,Relation설정)FrameWork/ORM 2024. 4. 24. 11:23
Sequelize 실전활용Update - catch~then 체인과 pk를 이용exports.postEditProduct = (req, res, next) => { const prodId = req.body.productId; const updatedTitle = req.body.title; const updatedPrice = req.body.price; const updatedImageUrl = req.body.imageUrl; const updatedDesc = req.body.description; Product.findByPk(prodId) .then( product =>{ product.title = updatedTitle; product.price ..
-
Prisma - Transactions과 다양한 부가기능FrameWork/ORM 2024. 4. 17. 10:35
Prisma에서 트랜잭션과 다양한 부가기능 Prisma - Doc/PrismaClient/Queries https://www.prisma.io/docs/orm/prisma-client/queries/transactions Transactions and batch queries (Reference) | Prisma Documentation This page explains the transactions API of Prisma Client. www.prisma.io 트랜잭션은 결과적으로 성공 또는 작동하지 않음이 보장되는 읽기/쓰기 작업이다. 트랜잭션이 상자속에 이루어진다고 상상해보자 격리된 상자속에서 SQL 문을 실행하는 것과 같다. 따라서 트랜잭션은 모든 명령문이 성공적으로 실행되거나 실행될 것임을 보..
-
Prisma - 객체 간의 관계 설정, 1:N, 1:1, N:MFrameWork/ORM 2024. 4. 16. 10:33
Prisma 객체간의 관계 설정 이번 게시물에서는 DB에서 자주 사용되고 블로그를 통해 많이 소개되었던 1대다(1:N), 1대1(1:1), 다대다(N:M) 관계들을 Prisma는 어떤 인터페이스를 사용해서 이를 설정할 수 있도록 하는지 알아볼것이다. 1 : N (One to Many Relations) 이 관계의 경우는 테이블 A의 하나의 레코드는 테이블 B의 여러 레코드와 관련되어 있다. 다만 테이블 B는 하나의 A의 레코드하고만 연결된다. 위 그림에서 와 같이 사용자는 여러번 주문을 할수 있다. 하지만 주문은 주문자로써의 사용자정보를 하나만 가진다. 1 : 1 (One to One Relations) 한명의 사용자는 하나의 프로필만 가지게 되고 프로필 입장에서도 하나의 사용자만 가지게 된다. N : ..
-
Prisma - 🐠시작하기 환경설정, 쿼리 로깅, CRUDFrameWork/ORM 2024. 4. 12. 10:52
Prisma 설정하기 [Quickstart] https://www.prisma.io/docs/getting-started/quickstart Quickstart with TypeScript & SQLite | Prisma Documentation Get started with Prisma ORM in 5 minutes. You will learn how to send queries to a SQLite database in a plain TypeScript script using Prisma Client. www.prisma.io nodeJs-express 서버에서 prisma 사용하기 prisma 의존성 설치 yarn add prisma --dev prisma init npx prisma init 이후..
-
Sequelize - 시퀄라이즈 시작 (설정,모델만들기,관계설정)FrameWork/ORM 2024. 3. 21. 15:52
Sequelize(시퀄라이즈) 시작 MySQL 테이블 생성 CREATE TABLE[데이터베이스명.테이블명]으로 테이블 생성 댓글 정보를 생성하는 테이블 create table comments( id int not null auto_increment, commenter int(11) not null, comment varchar(100) not null, created_at datetime not null default now(), primary key (id), INDEX commenter_idx (commenter ASC), CONSTRAINT commenter foreign key (commenter) references users(id) ON DELETE CASCADE ON UPDATE CASCAD..
-
ExpressJS - express.js 활용2(Multer, Router, req와 res객체)FrameWork/Express.js 2024. 3. 20. 08:54
express.js 파일 업로드 하기 multer 이미지, 동영상등을 비롯한 여러가지 파일들을 멀티파트 형식으로 업로드할 때 사용하는 미들웨어이다. 멀티파티 형식이란 enctype이 multipart/form-data인 폼을 통해 업로드하는 데이터의 형식을 의미한다. form 태그의 enctype이 multipart/form-data인 경우 body-parser로는 요청 본문을 해석할 수 없음 multer 패키지 필요 업로드 multer 함수를 호출 storage는 저장할 공간에대한 정보 diskStorage는 하드디스크에 업로드 파일을 저장한다는 것 destination은 저장할 경로 filename은 저장할 파일명(파일명+날짜+확장자 형식) Limits는 파일 개수나 파일 사이즈를 제한할 수 있다. ..
-
ExpressJS - express.js 활용1(next활용법, 자주 쓰는 미들웨어)FrameWork/Express.js 2024. 3. 19. 14:57
express.js 활용 next 활용법 res.json과 return의 차이 // 라우터에 return이 없는 경우 app.get('/',(req, res) =>{ res.json({hello:'express'}); console.log('hello express'); }); // 라운터에 return이 있는 경우 app.get('/',(req, res) =>{ return res.json({hello:'express'}); console.log('hello express'); }); res.json(), res.send()메서드를 return과 동일시 하기 쉬운데 엄밀히 말하면 res.json과 return은 다르다. 우선 res.json()은 응답을 보낼 뿐이지 함수를 끝내는 것은 아니다. 그래서 ..
-
ExpressJS - express.js 서버 시작하기(setting, 미들웨어)FrameWork/Express.js 2024. 3. 18. 15:55
express.js 서버 시작하기 ExpressJS로 HTML 서빙하기 index.html 익스프레스 배워봅시다. app.js const express = require('express'); const app = express(); // 서버에 port라는 변수를 심는다. // 전역 변수의 개념 app.set('port',process.env.PORT||3400); app.get('/',(req, res) => { res.sendFile('./index.html'); }); app.listen(app.get('port'),() => { console.log(app.get('port'),'번 포트에서 대기 중') }); sendFile() 메서드를 사용하면 express에서 알아서 fs 패키지를 사용해서 ..