QuestionI've seemed to try all possible ways (myself / codex 5.2 / claude 4.5) to use Prisma 7.3 with NestJS (v11) Is it possible without making a big mess ? How to reproduce (optional)No response Expected behavior (optional)No response Information about Prisma Schema, Client Queries and Environment (optional)No response |
Replies: 3 comments 2 replies
|
It works perfectly for me with NestJS 11. What's wrong with it? Please provide more information. |
|
This repository had NestJS examples with Prisma 7 which you can use as a reference: |
|
Prisma 7 works perfectly fine with NestJS 11. The key difference from v6 is that the new Here's a clean setup: 1. Schema ( generator client {
provider = "prisma-client"
output = "../src/generated/prisma"
}2. PrismaService: // src/prisma/prisma.service.ts
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common'
import { PrismaClient } from '../generated/prisma/client'
@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
async onModuleInit() {
await this.$connect()
}
async onModuleDestroy() {
await this.$disconnect()
}
}3. PrismaModule: // src/prisma/prisma.module.ts
import { Global, Module } from '@nestjs/common'
import { PrismaService } from './prisma.service'
@Global()
@Module({
providers: [PrismaService],
exports: [PrismaService],
})
export class PrismaModule {}4. Use it anywhere: @Injectable()
export class UsersService {
constructor(private prisma: PrismaService) {}
findAll() {
return this.prisma.user.findMany()
}
}The only thing that might trip you up: if you use function extendedPrismaClient() {
const client = new PrismaClient().$extends(/* your extensions */)
return class {
constructor() { return client }
} as new () => typeof client
}
@Injectable()
export class PrismaService extends extendedPrismaClient() implements OnModuleInit {
async onModuleInit() { await this.$connect() }
}This approach is well-tested and used in production. No "big mess" required. |
This repository had NestJS examples with Prisma 7 which you can use as a reference:
https://github.com/prisma/prisma-examples