Skip to content

Instantly share code, notes, and snippets.

@d-exclaimation
Created October 17, 2022 03:07
Prisma + Nest.js
import { Module } from "@nestjs/common";
import { PrismaService } from "./prisma.service";
@Module({
providers: [PrismaService],
exports: [PrismaService]
})
export class PrismaModule {}
import { INestApplication, Injectable, OnModuleInit } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit {
async onModuleInit() {
await this.$connect();
}
async enableShutdownHooks(app: INestApplication) {
this.$on("beforeExit", async () => {
await app.close();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment