Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Tranactional 모듈을 NPM 라이브러리로 분리 #265

Conversation

takeny1998
Copy link
Collaborator

작업 개요

파일 API에도 Prisma를 추가할 것임에 따라, 메인 API의 TransactinoModule을 별도의 NPM 패키지로 분리했습니다. 이를 메인 API에 테스트해보고, 교체를 완료했습니다.

작업 사항

  • 트랜잭션 모듈을 재사용 가능하게 NPM 모듈로 분리했습니다.
  • 레파지토리 및 테스트코드에서 사용하는 PrismaService를 교체했습니다.
  • rawQuery를 지원하지 않는 문제를 해결했습니다.

고민한 점들

Raw Query가 왜 지원하지 않을까?

 ...
    {
      provide: PRISMA_SERVICE,
      useValue: new PrismaService().$extends(txExtension),
    },
  ],
  exports: [PRISMA_SERVICE],

Raw Query를 어떻게 지원할 수 있을까?

       ...
        if (operation === '$queryRaw') {
          const result = await store.txClient[operation](args);

          (result as any).forEach((row: Record<string, unknown>) => {
            Object.keys(row).map((key) => {
              row[key] = {
                prisma__type: undefined,
                prisma__value: row[key],
              };
            });
          });

          return result;
        }

- 기존 코드를 별도의 NPM 라이브러리로 이관하였음
(https://www.npmjs.com/package/@takeny1998/nestjs-prisma-transactional)
- 분리된 NPM 패키지를 추가하고 yarn으로 설치
- 기존 TransactionModule을 제거하고, 패키지의 모듈로 교체하였음
- Prisma 확장을 App 모듈에 선언하고, 전역으로 Export 하였음
- Inject 토큰 사용해, 기존 TxPrisma를 PrismaService로 교체해 주입하였음
@takeny1998 takeny1998 added REFACTOR 리펙토링 BE 백엔드 labels Jan 3, 2024
@takeny1998 takeny1998 merged commit b656020 into boostcampwm2023:develop Jan 11, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BE 백엔드 REFACTOR 리펙토링
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant