PrismaP
Prisma5mo ago
4 replies
igor_quintal

Casting Postgres BigInt as TS Number

Hi everyone!
I'm using Prisma on my Nest JS application that connects to a Postgres Database. Some fields in this DB are all BIGINT, and Prisma returns them as JS's BigInt. I undertand that in some cases, TS Number may not be able to handle such large numbers as BigInt. But using Number for Postgres BIGINT seems ok for most of the time, since Number supports up to quadrillions. My team and I are trying to figure out a way to return all BIGINT columns as Numbers, since integrating our DB with Prisma is generating some problems (a lot of arithmetic operations are breaking and serialization is not working).

I have tried using middlewares, but they can only provide a new column with the value as a number, not override the original column. I have also read about updating pg_types default bigint parser, but was unable to do so in Prisma. Do you have any recommendations? This is really generating a lot of hassle on our projects since updating the ORM is requiring a lot of changes on code.
Was this page helpful?