DEV Community

Benny Halperin
Benny Halperin

Posted on

Breaking changes in Prisma Client v6.14

If you are using Prisma ORM in your NestJS project and created your own custom Prisma service that extends the generated Prisma client, please read on.

Up until Prisma v6.13, your custom service followed this pattern:

import { PrismaClient } from 'my/generated/prisma/client/path';

export class PrismaService extends PrismaClient implements OnModuleInit {
...
Enter fullscreen mode Exit fullscreen mode

Compiling this code with Prisma v6.14 generates an error. To fix it, your custom service should no longer extend PrismaClient. Instead, declare a public property of type PrismaClient and instantiate it in the constructor. This will be the client referenced elsewhere in your code to run database queries.

The new pattern:

import { PrismaClient } from 'my/generated/prisma/client/path';

export class PrismaService implements OnModuleInit {
    readonly client: PrismaClient;

    constructor() {
        this.client = new PrismaClient();
    }
...
Enter fullscreen mode Exit fullscreen mode

Then elsewhere in your code:

@Injectable()
export class UsersService {
    constructor(
        private prisma: PrismaService,
    ) {}

    async getUsers() {
        return await this.prisma.client.user.findMany();
        /* PREVIOUSLY: return await this.prisma.user.findMany(); */
    }
Enter fullscreen mode Exit fullscreen mode

Hopes this helps.

Top comments (0)