Last active
February 17, 2024 15:25
-
-
Save asror797/20c9b11bd77863fd90cc5c9732c137d6 to your computer and use it in GitHub Desktop.
Nest.js and Prisma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Module } from "@nestjs/common"; | |
import { PrismaService } from "./prisma.service"; | |
@Module({ | |
providers: [PrismaService], | |
exports: [PrismaService] | |
}) | |
export class PrismaModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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