TypeORM

TypeORM 실무 — Raw Query를 ORM으로 변환CRUD 비교전체 조회// Raw SQLconst [users] = await pool.query('SELECT * FROM users');// TypeORMconst users = await userRepository.find();단건 조회// Raw SQLconst [rows] = await pool.query('SELECT * FROM users WHERE id = ?', [id]);const user = rows[0];if (!user) throw new Error('Not found');// TypeORMconst user = await userRepository.findOne({ where: { id } });if (!user) thro..
TypeORM 기초ORM(Object-Relational Mapping) = 객체와 테이블을 연결해주는 것. SQL 대신 TypeScript 코드로 DB를 조작한다.설치 & 세팅npm install typeorm reflect-metadata mysql2tsconfig.json:{ "compilerOptions": { "experimentalDecorators": true, "emitDecoratorMetadata": true }}src/data-source.ts:import { DataSource } from 'typeorm';export const AppDataSource = new DataSource({ type: 'mysql', host: 'localhost', port: 33..
sooyoung.c.dev
'TypeORM' 태그의 글 목록