You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support Unsupported Types inside Prisma Client (not just Prisma Migrate) #5683
Rather than addressing each of these types (which still needs to be done in the long run), find a solution to let the user (dev) hook into prisma with a callback function to support the type. Think of how graphqljs (and nexus) does custom scalars. In the nexus docs you will find that there's a callback hook for parseValue, serialize and parseLiteral
What if we could do the same with unsupported types in prisma. Let's say we got a prisma schema with a TimeEntry model using postgres, with duration column that uses interval type on postgres.
It would be great if we could read the timeEntry including the unsupported duration column with code such as below:
constfindAll=async()=>prisma.timeEntry.findMany({customColumns: {duration: {castTo: 'text'// adds duration::text in postgres query,parse: moment.duration// custom function to parse the output from postgres before returning the promise}}})
Additional context
See #4045 for related discussion, especially my comment here
Reacted by Benjamin Tran Dinh, benknab, Justas Palumickas, Alexey Murz Korepov, Ali, Chris Lambe, Clovis de Villars, Keyan, Drew Vartanian, Victor Arowo and 31 more
This would also help developers ensure transactionality while using the prisma API when a model with an unsupported type has to be updated together with regular prisma models because right now both nested writes and prisma.$transaction are insufficient for this use case.
See discussion: #5804
changed the title [-]Support `unsupportedTypes` inside prisma client (not just prisma migrate)[/-][+]Support `Unsupported` Types inside Prisma Client (not just Prisma Migrate)[/+]on Feb 6, 2022
In order to not open another ticket relating the Unsupported field support, I'll post some related information and hope the team settle on the best workaround that won't cause them pain in the long-term..
Related Issue for the underlying engine doing the type conversion: prisma/quaint#64
Schema level casting:
// Idea 1 - Prisma is an abstraction of the database, so why not leverage this:
randomLocation @Unsupported("point")
randomLocationVirtual String @convert(field: randomLocation, select: “$::TEXT”) // $ references the value of the field?
// Idea 2 - leave the dev to format on select/update
randomLocation String @Unsupported("point")
// Janpio’s suggestion:
randomLocation Unsupported("point") @client.cast/fallback(string)
// Similar but cleaner?
randomLocation Unsupported("point") @cast(type: String)
The more I look at the typing, the more I see this is not mainly a PostGIS type problem, without a solution then you'll always be chasing your tail to support new types, especially if the plan is to support more databases.
A big question is if you can provide the needed flexibility in the schema definition alone, or if as suggested above, you need the devs to write the handlers.
String casting could also be implemented behind a previewFeature such as "unsupported-string-autocast" to fix this until you have time for a long-term solution?
Reacted by Roman Savaryn, Jesus Galvan, Luca Campli, Illia and keinsell
Activity
benknab commentedon Feb 24, 2021
This would also help developers ensure transactionality while using the prisma API when a model with an unsupported type has to be updated together with regular prisma models because right now both nested writes and
prisma.$transactionare insufficient for this use case.See discussion: #5804
benjamintd commentedon Mar 15, 2021
From a developer point of view, and using postgis fields as an example, here's what I think the API could look like:
[-]Support `unsupportedTypes` inside prisma client (not just prisma migrate)[/-][+]Support `Unsupported` Types inside Prisma Client (not just Prisma Migrate)[/+]stevenkissack commentedon Mar 10, 2022
In order to not open another ticket relating the Unsupported field support, I'll post some related information and hope the team settle on the best workaround that won't cause them pain in the long-term..
Related Issue for the underlying engine doing the type conversion: prisma/quaint#64
Schema level casting:
The more I look at the typing, the more I see this is not mainly a PostGIS type problem, without a solution then you'll always be chasing your tail to support new types, especially if the plan is to support more databases.
A big question is if you can provide the needed flexibility in the schema definition alone, or if as suggested above, you need the devs to write the handlers.
String casting could also be implemented behind a previewFeature such as "unsupported-string-autocast" to fix this until you have time for a long-term solution?