You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Repository는 Entity에 대한 CRUD를 관리한다.
의존성 주입을 위해 @InjectRepository() 를 사용한다.
Repository API
위 공식문서에서 기본적인 CRUD 서비스 내용을 긁어왔다.
create
Creates a new instance of User. Optionally accepts an object literal with user properties which will be written into newly created user object
const user = repository.create() // same as const user = new User();
const user = repository.create({
id: 1,
firstName: "Timber",
lastName: "Saw",
}) // same as const user = new User(); user.firstName = "Timber"; user.lastName = "Saw";
Partially updates entity by a given update options or entity id.
await repository.update({ age: 18 }, { category: "ADULT" })
// executes UPDATE user SET category = ADULT WHERE age = 18
await repository.update(1, { firstName: "Rizzrak" })
// executes UPDATE user SET firstName = Rizzrak WHERE id = 1
delete
Deletes entities by entity id, ids or given conditions:
const repository = dataSource.getRepository(Entity)
// Delete a entity
await repository.softDelete(1)
// And You can restore it using restore;
await repository.restore(1)
📕Repository Pattern
Repository는 Entity에 대한 CRUD를 관리한다.
의존성 주입을 위해
@InjectRepository()
를 사용한다.Repository API
위 공식문서에서 기본적인 CRUD 서비스 내용을 긁어왔다.
create
save
find
findOne
findOneBy
update
delete
softDelete and restore
📘QueryBuilder Pattern
SQL 쿼리문들을 이용하여 조건들이 반영된 Entitiy를 얻을수 있도록한다.
예를 들어 이 구문의 결과는
다음과 같다.
사용 예시는 좋은 글이 있어 첨부로 대신합니다.
[NestJS/TypeORM] QueryBuilder for NestJS (TypeORM Refactoring)
The text was updated successfully, but these errors were encountered: