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

BigInt Type Issue #21

Open
develjsw opened this issue Oct 16, 2024 · 0 comments
Open

BigInt Type Issue #21

develjsw opened this issue Oct 16, 2024 · 0 comments

Comments

@develjsw
Copy link
Owner

develjsw commented Oct 16, 2024

  1. 이슈 :

    • 회사에서 BigInt 타입을 사용하게 되었으며, 이를 Prisma ORM을 통해 데이터를 저장하거나 응답 값을 반환할 때 에러가 발생
    • 응답할 때 BigInt 값은 숫자n 형식으로 반환됨. 즉, Prisma에서 BigInt 타입이 그대로 반환 되면서, JSON 직렬화 시 문제가 발생
  2. 원인 :

    • JSON 형식은 BigInt 타입을 지원하지 않음. 따라서 Prisma에서 BigInt 값을 반환할 때 숫자n 형식(예: 12345n)으로 반환 되며, 이를 JSON 직렬화(JSON.stringify)할 때 에러가 발생함
    • JSON 타입의 컬럼에 데이터를 저장할 때, BigInt는 지원되지 않아서 저장 불가
    • BigInt 타입을 포함한 데이터를 응답으로 반환할 때, BigInt 값이 숫자n 형식 그대로 전달되기 때문에 JSON 변환 과정에서 에러가 발생
  3. 해결 방안 :

    • 응답 시: BigInt 값을 숫자(number)로 변환하여 반환.
      이를 통해 BigInt가 클라이언트로 전달되기 전에 직렬화 문제가 해결됨.
      (BigInt를 number로 변환하는 interceptor를 구현하여 일괄 적용되도록 함)
    • 저장 시: BigInt 값JSON.stringify()로 문자열로 변환하여 저장.
      Prisma에서 BigInt를 지원하지 않는 JSON 컬럼에 저장할 때, 문자열로 변환하여 안전하게 저장

참고 사항 :

  • TypeORM에서는 응답할 때 BigInt 값이 숫자n 형식으로 반환되지 않고 숫자 형식으로 반환됨
  • TypeORM에서도 기본적인 BigInt 이슈는 동일하게 발생
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant