22 lines
509 B
TypeScript
22 lines
509 B
TypeScript
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
|
|
import { PrismaClient } from '@prisma/client';
|
|
|
|
@Injectable()
|
|
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
|
|
constructor() {
|
|
super({
|
|
log: process.env.NODE_ENV === 'development'
|
|
? ['query', 'info', 'warn', 'error']
|
|
: ['error'],
|
|
});
|
|
}
|
|
|
|
async onModuleInit() {
|
|
await this.$connect();
|
|
}
|
|
|
|
async onModuleDestroy() {
|
|
await this.$disconnect();
|
|
}
|
|
}
|