import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common'; import { PrismaClient } from '@prisma/client'; /** * Global Prisma client wrapper. * * - `onModuleInit`: connects to the database so the first request * does not pay the connection cost. * - `onModuleDestroy`: cleanly disconnects during shutdown. */ @Injectable() export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy { async onModuleInit(): Promise { await this.$connect(); } async onModuleDestroy(): Promise { await this.$disconnect(); } }