Fixing file name casing
This commit is contained in:
9
src/Prisma/prisma.module.ts
Normal file
9
src/Prisma/prisma.module.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { PrismaService } from './prisma.service';
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
providers: [PrismaService],
|
||||
exports: [PrismaService],
|
||||
})
|
||||
export class PrismaModule {}
|
||||
49
src/Prisma/prisma.service.ts
Normal file
49
src/Prisma/prisma.service.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import {
|
||||
ConsoleLogger,
|
||||
INestApplication,
|
||||
Injectable,
|
||||
OnModuleInit,
|
||||
} from '@nestjs/common';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
@Injectable()
|
||||
export class PrismaService extends PrismaClient implements OnModuleInit {
|
||||
private readonly logger = new ConsoleLogger(PrismaService.name);
|
||||
|
||||
constructor() {
|
||||
super({
|
||||
log: [
|
||||
{
|
||||
emit: 'stdout',
|
||||
level: 'query',
|
||||
},
|
||||
{
|
||||
emit: 'stdout',
|
||||
level: 'error',
|
||||
},
|
||||
{
|
||||
emit: 'event',
|
||||
level: 'info',
|
||||
},
|
||||
{
|
||||
emit: 'stdout',
|
||||
level: 'warn',
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
async onModuleInit() {
|
||||
this.logger.log('Try to connect database...');
|
||||
|
||||
await this.$connect();
|
||||
this.logger.log('Connected.');
|
||||
}
|
||||
|
||||
async enableShutdownHooks(app: INestApplication) {
|
||||
this.$on('beforeExit' as never, async () => {
|
||||
this.logger.log('Wait for application closing...');
|
||||
await app.close();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user