Active Record vs Data Mapper

Kim Seungchan·2023년 11월 21일

@EntityRepository의 Deprecated

TypeORM 0.3.X 버전부터 @EntityRepository 데코레이터의 사용이 금지되었다.

해당 데코레이터는 Custom Repository 패턴을 사용하기 위해 사용해왔다.

그렇다면 어떤 이유로 deprecated 되었을까?

TypeORM 을 사용하는 대다수의 개발자들이 Service Layer 에는 비즈니스 로직만을 작성하고 Repository Layer 에는 쿼리 로직을 작성한다. (중략) 그러다보니... 아래와 같이 메소드를 불필요하게 생성해 사용하는 케이스가 생기기 시작했다.

// User Repository
@EntityRepository(User)
class UserRepository extends Repository<User> {
  async getAllUsers() {
    return this.find()
  }
}

위와 관련하여 여러 개발자들이 엄격한 Data Mapper 패턴의 사용이 좋지 않다는 목소리를 냈고, 이에 TypeORM 관리팀은 @EntityRepository 데코레이터를 Deprecated 하며 Active Record 패턴을 권장하는 듯한 뉘앙스를 풍기는 메시지를 남겼다.

지금부터 Active Record 패턴과 Data Mapper 패턴이 무엇인지 알아보자.

Active Record 패턴

https://orkhan.gitbook.io/typeorm/docs/active-record-data-mapper#what-is-the-active-record-pattern

Data Mapper 패턴

https://orkhan.gitbook.io/typeorm/docs/active-record-data-mapper#what-is-the-active-record-pattern

결론

두 패턴 모두 장점이 있다.

Data Mapper 패턴은 유지관리성(maintainability)에 도움을 주는데, 큰 앱에서 더 효과적이다.

Active Record 패턴은 작은 앱에서도 잘 작동하는 단순함에 도움을 준다. 그리고 단순함(simplicity)은 항상 더 나은 유지관리성(maintainability)을 위한 열쇠이다.

Reference

사라진 데코레이터, @EntityRepository (by. TypeORM 0.3.X)
Active Record vs Data Mapper

profile
기묘한 개발자 지망생

0개의 댓글