Is there a non-hacky way to hash all IDs before returning to the user? I have explored the documentation extensively but haven't found a solution that covers all scenarios.
I am working with Postgres and Prisma ORM, managing multiple models with relational fields. Ideally, I want to achieve this using Prisma.
I attempted Jordan's suggestion, resulting in the following code:
const getPrismaClient = () => {
const client = new PrismaClient();
client.$extends({
result: {
blog: {
// Creating a virtual `hashedId` field
hashedId: {
needs: { id: true },
compute(client) {
return intToHashedString(client.id);
},
},
},
},
});
client.blog
.findMany({
select: { hashedId: true },
})
.then((r) => {
console.log(r);
});
return client;
};
However, it resulted in the following error:
error - unhandledRejection: PrismaClientValidationError:
Invalid `prisma.blog.findMany()` invocation:
{
select: {
hashedId: true,
~~~~~~~~
? id?: true,
? title?: true,
? slug?: true,
? image?: true,
? description?: true,
? views?: true,
? authorId?: true,
clientVersion: '4.11.0'
}