Files
AFFiNE-Mirror/packages/backend/server/src/fundamentals/prisma/service.ts
T
2024-03-26 02:24:17 +00:00

28 lines
601 B
TypeScript

import type { OnModuleDestroy, OnModuleInit } from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
@Injectable()
export class PrismaService
extends PrismaClient
implements OnModuleInit, OnModuleDestroy
{
static INSTANCE: PrismaService | null = null;
constructor() {
super();
PrismaService.INSTANCE = this;
}
async onModuleInit() {
await this.$connect();
}
async onModuleDestroy(): Promise<void> {
if (!AFFiNE.node.test) {
await this.$disconnect();
PrismaService.INSTANCE = null;
}
}
}