Hello! I’ve just started to look into using Prisma...
# orm-help
c
Hello! I’ve just started to look into using Prisma across all my future projects as it offers the migration, seeding and simple but powerful API that I’ve been looking for. But I’m having a lot of trouble with BigInt (I’ve seen a lot of posts about this already) and typing within React/TypeScript projects. I understand that the BigInt to JSON issue seems to be a problem with JavaScript itself not being able to transpose it correctly, Should I instead use Int instead for my DB ID’s? The typing issue comes when I’m trying to share types between backend and frontend (currently using Next.js and API Routes), anytime I transpose the data to JSON most of the types are lost (BigInt, DateTime etc) and I haven’t figured out a way to carry these types across without writing them out, which kinda defeats the purpose of using that feature of Prisma. Would love to hear some thoughts or ideas of how to get around these issues
👀 1
a
Hey Charlie!
Should I instead use Int instead for my DB ID’s?
That’s really dependent on your application’s needs, but it’s very common to see both
Int
and
String
used for database ID’s.
The typing issue comes when I’m trying to share types between backend and frontend
This is a common issue and a definite drawback when trying to reuse database types on the frontend. To assist with the actual implementation of the serialize/deserialize process, I’ve seen folks use packages like
superjson
which will handle
BigInt
and
Date
for you, but I’m not sure how it handles the TypeScript definitions. Most people derive new types based off the Prisma types or write utility types that convert non-serializable types into `string`s.
c
Cheers for the answer. I know Prisma isn’t just a JS toolset but it feels like a big shortcoming to have to wrap an output and rewrite types 😞. I’ll take a look at superjson, and if you’ve got any links to type converters that would be ace!
👍 1