TypeOrm remove() 와 delete() 의 차이

혀느현스·2023년 2월 2일
2
post-thumbnail

tl;dr

// remove - 주어진 엔티티를 지운다
this.repository.remove(entity) 
this.repository.softRemove(entity)

// delete - 조건으로 지운다
this.repository.delete({id: id}) 
this.repository.softDelete({id: id})

remove() - 엔티티를 지운다

Removes a given entities from the database.
주어진 엔티티들을 데이터베이스에서 삭제합니다.
- remove() 의 툴팁

remove()엔티티를 가지고 있을 때, 이를 삭제하기 위해 사용합니다.

this.repository.remove(entity)
this.repository.remove([entity1, entity2])

만약 해당 엔티티가 데이터베이스에 존재하지 않으면 오류를 발생시킵니다.

delete() - 조건으로 지운다

Deletes entities by a given criteria. Unlike save method executes a primitive operation without cascades, relations and other operations included. Executes fast and efficient DELETE query. Does not check if entity exist in the database.
조건을 바탕으로 엔티티를 삭제합니다. save() 메소드와 달리 cascades와 relations 및 기타 작업을 포함하지 않은 원시적인 작업을 실행합니다. 빠르고 효율적인 DELETE 쿼리를 실행합니다. 데이터베이스에 엔티티가 있는지 확인하지 않습니다.
- delete() 의 툴팁

delete() 는 조건을 받아서 DELETE 쿼리를 실행합니다.

조건에 해당하는 엔티티가 없더라도 오류를 발생시키지 않습니다.

profile
새로운 상상을 하고, 상상을 현실로 만드는 개발자

0개의 댓글