26 lines
506 B
TypeScript
26 lines
506 B
TypeScript
import { Injectable, OnModuleInit, OnModuleDestroy } from "@nestjs/common";
|
|
import { PrismaClient } from "@prisma/client";
|
|
|
|
@Injectable()
|
|
export class DatabaseService implements OnModuleInit, OnModuleDestroy {
|
|
private prisma: PrismaClient;
|
|
|
|
constructor() {
|
|
this.prisma = new PrismaClient({
|
|
log: ["query", "error", "warn"],
|
|
});
|
|
}
|
|
|
|
onModuleInit() {
|
|
this.prisma.$connect();
|
|
}
|
|
|
|
onModuleDestroy() {
|
|
this.prisma.$disconnect();
|
|
}
|
|
|
|
getPrisma() {
|
|
return this.prisma;
|
|
}
|
|
}
|