DEV/TypeORM(4)
-
TypeORM Migration하기
Migration package.json에 설정된 명령어를 참고하자. "scripts": { "db:migrate": "yarn typeorm migration:generate -- -n", "db:up": "yarn typeorm migration:run", "db:down": "yarn typeorm migration:revert", "db:migrate:prod": "yarn typeorm:prod migration:generate -- -n", "db:up:prod": "yarn typeorm:prod migration:run", "db:down:prod": "yarn typeorm:prod migration:revert" }, Version 확인 프로젝트 버전과 데이터 베이스의 버전이 같은 지 ..
2020.10.06 -
TypeORM Relations
Relations 관계형 Entity 설계 1:1 : @OneToOne N:1 : @ManyToOne 1:N : @OneToMany N:N : @ManyToMany One-To-One 서로 1:1로만 매칭이 되는 모델에 사용 관계 설정 @OneToOne Target Type을 지정하여 연결 설정 단방향/양방향 설정 가능 단방향 : 한쪽에만 설정 양방향 : 양쪽에 설정 @JoinColumn 관계 중 Foreign Key가 있는 쪽에 설정 필수 설정된 테이블에 "relation id"와 foreign key가 저장됨 import {Entity, PrimaryGeneratedColumn, Column} from "typeorm"; @Entity() export class Profile { @PrimaryGen..
2020.10.04 -
TypeORM Entity
Entity 데이터베이스에 매핑되는 클래스 : Table, Collection 등 Embedded Entities 기본 생성 @Entity 로 표기하고 @Column 으로 항목 설정 import {Entity, PrimaryGeneratedColumn, Column} from "typeorm"; @Entity() export class User { @PrimaryGeneratedColumn() id: string; @Column() firstName: string; @Column() lastName: string; @Column() isActive: boolean; } Import 기능 반복되는 항목을 별도 클래스로 생성하여 코드 간단화 가능 import {Column} from "typeorm"; ex..
2020.10.03 -
TypeORM Pattern
TypeORM이란? TypeORM is an ORM that can run in NodeJS, Browser, Cordova, PhoneGap, Ionic, React Native, NativeScript, Expo, and Electron platforms and can be used with TypeScript and JavaScript (ES5, ES6, ES7, ES8). Its goal is to always support the latest JavaScript features and provide additional features that help you to develop any kind of application that uses databases - from small applicati..
2020.10.02