-
-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possibility to use extensions and this.prisma. #88
Comments
+1 would be great to have extensions support |
@shreyassood Prisma extensions are already supported: https://nestjs-prisma.dev/docs/prisma-client-extensions/ @famouzkk I haven't found a way to make this possible. The default // simplified
import { Inject, Injectable, OnModuleInit, Optional } from '@nestjs/common';
import { Prisma, PrismaClient } from '@prisma/client';
import { PrismaServiceOptions } from './interfaces';
import { PRISMA_SERVICE_OPTIONS } from './prisma.constants';
@Injectable()
export class PrismaService extends PrismaClient {
constructor(
@Optional()
@Inject(PRISMA_SERVICE_OPTIONS)
private readonly prismaServiceOptions: PrismaServiceOptions = {},
) {
super(prismaServiceOptions.prismaOptions);
}
} That allows to access @Injectable()
export class AppService {
constructor(private prisma: PrismaService) {}
users() {
return this.prisma.user.findMany();
}
} However, with Prisma extensions it is not possible to extend the service with the applied extension. Open issue about this: prisma/prisma#18628 My solution is to provide the Prisma Client with the extension via the @Injectable()
export class CustomPrismaService<Client extends PrismaClientLike> {
constructor(
@Inject(CUSTOM_PRISMA_CLIENT)
public client: Client,
) {}
} This approach requires to access the client @Injectable()
export class AppService {
constructor(
// ✅ use `ExtendedPrismaClient` from extension for correct type-safety
@Inject('PrismaService')
private prisma: CustomPrismaService<ExtendedPrismaClient>,
) {}
users() {
return this.prisma.client.user.findMany();
}
} If you have a solution, I am always open for ideas or a PR. |
Is it possible to use extensions and still access the Prisma client using
this.prisma.
instead ofthis.prisma.client.
?The text was updated successfully, but these errors were encountered: