728x90
typeorm에서 merge 예제
데이터가 있을 경우 update, 없을 경우 insert를 처리 하는 코드 예제 입니다.
await this.eventsRepository
.createQueryBuilder()
.insert()
.into(Event)
.values(event)
.orUpdate({ conflict_target: ['wp_id'], overwrite: ['cntnt', 'srch_wrd_seq', 'writr_nm', 'writr_id', 'tgtr_nm', 'tgtr_id', 'mod_dtm'] })
.execute();
orUpdate의 conflict_target에 중복 키 값을 넣고 update할 목록을 overwrite에 넣으면 됩니다.
여기서 주요한건, 모두 DB필드 기준
으로 입력하여야 합니다.
참고자료
'NodeJS' 카테고리의 다른 글
NAVER CLOUD PLATFORM API를 Typescript 기반에서 사용하기 (0) | 2021.02.13 |
---|---|
Nestjs tutorial (0) | 2021.01.11 |
Mongoose에서 Array 내용 수정 후 .save()를 호출해도 동작하지 않는 현상 (0) | 2021.01.10 |
nestjs에서 passport를 이용해서 로그인 하는 기능을 확인해보았습니다. (0) | 2021.01.09 |
JS] typeof를 이용해서 선언되지 않은 변수 확인 (0) | 2021.01.09 |