Skip to content

Instantly share code, notes, and snippets.

@asror797
Last active February 17, 2024 15:25
Show Gist options
  • Save asror797/20c9b11bd77863fd90cc5c9732c137d6 to your computer and use it in GitHub Desktop.
Save asror797/20c9b11bd77863fd90cc5c9732c137d6 to your computer and use it in GitHub Desktop.
Nest.js and Prisma
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