P
Prisma•3mo ago
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.
3 Replies
Prisma AI Help
Prisma AI Help•3mo ago
You chose to debug with a human. They'll tinker with your query soon. If you get curious meanwhile, hop into #ask-ai for a quick spin!
Nurul
Nurul•3mo ago
Did you had a look at this GitHub Discussion? https://github.com/prisma/prisma/discussions/20188 Perhaps this can work for you as a workaround?
GitHub
Transform BigInt fields to number or string globally (maybe v...
Hey! I have BigInt fields in my schema (PostgreSQL) which are not nice to use in React code. The workarounds I've seen all seem hacky to me and are only ad-hoc solutions when using the data (in...
igor_quintal
igor_quintalOP•3mo ago
This appears to only change the JSON.stringify method. But Prisma queries still return BigInt instead of Number 😢 if there any other workaround would be so much appreciated. This has really be bringing a lot of hassle to my project

Did you find this page helpful?