Stephen
Stephen
PPrisma
Created by Stephen on 2/18/2025 in #help-and-questions
NestJS with Optimize not working
Hey everyone! I am currently looking to add Optimize to my NestJS app. Can you guys help me out figuring out why I am not receiving anything in my optimize? I am using the following libraries and version: - "@prisma/client": "^6.4.0", - "prisma": "^6.4.0", - "@prisma/extension-optimize": "^1.1.4", - "@prisma/instrumentation": "^6.4.0", I know I don't have to use the preview anymore in my prisma schema. Here is my prisma.service.ts:
import {
Global,
Injectable,
OnModuleDestroy,
OnModuleInit,
} from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
import { withOptimize } from '@prisma/extension-optimize';

@Global()
@Injectable()
export class PrismaService
extends PrismaClient
implements OnModuleInit, OnModuleDestroy
{
constructor() {
super();
this.$extends(
withOptimize({ apiKey: process.env.PRISMA_OPTIMIZE_API_KEY! }),
);
}

async onModuleInit() {
await this.$connect();
}

async onModuleDestroy() {
await this.$disconnect();
}
}
import {
Global,
Injectable,
OnModuleDestroy,
OnModuleInit,
} from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
import { withOptimize } from '@prisma/extension-optimize';

@Global()
@Injectable()
export class PrismaService
extends PrismaClient
implements OnModuleInit, OnModuleDestroy
{
constructor() {
super();
this.$extends(
withOptimize({ apiKey: process.env.PRISMA_OPTIMIZE_API_KEY! }),
);
}

async onModuleInit() {
await this.$connect();
}

async onModuleDestroy() {
await this.$disconnect();
}
}
7 replies