Open jymchng opened 1 year ago
Your issue is with the extension mechanism.
NestJS uses a class that inherits from the PrismaClient, but applying extensions require to use the return value of $extends()
, so applying extensions in the derived class constructor won't work.
There are issues on the Prisma repo about how to deal with Nest and extensions, you should be able to find a solution there.
Your issue is with the extension mechanism.
NestJS uses a class that inherits from the PrismaClient, but applying extensions require to use the return value of
$extends()
, so applying extensions in the derived class constructor won't work.There are issues on the Prisma repo about how to deal with Nest and extensions, you should be able to find a solution there.
Thanks for your reply @franky47, https://github.com/prisma/prisma/issues/20833
@franky47 Btw, do you have a quick workaround? Or can you point me more directly to issues that have some quick solutions?
Thank you sir!
@franky47 Sir, would it be better practice to have two PrismaService, one specifically for creating records for tables with encrypted column(s) and another for general database operations? I see the link that you shared requires me to purposefully inject the CustomPrismaService whenever I need it.
constructor(
// ✅ use `extendedPrismaClient` type for correct type-safety of your extended PrismaClient
@Inject('PrismaService')
private prismaService: CustomPrismaService<extendedPrismaClient>
) {}
That sounds like a recipe for disaster, as a lot can go wrong: overwriting encrypted records with clear-text values (leaking data), or sending ciphertext to the front-end.
The extension makes operations transparent, so inject it to configure your client and you can forget about it being here (albeit losing some features like partial search and sorting on encrypted fields).
@franky47 Thank you for your reply, oh, I am just trying to encrypt one or two columns of some of my tables, I am not sure how I can actually 'inject it to configure your client', is the example in the documentation sufficient? I read it.
I am trying to encrypt a particular field in my Prisma model.
Here is the full codes of my
PrismaService
residing my in NestJS'sPrismaModule
:On my
prisma.schema
:Within my database, after using
prismaService.user.create
, the resulting entry in the PostgreSQL database is NOT encrypted.Any idea how does it work? Thank you.