mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-06 03:49:56 +08:00
28 lines
601 B
TypeScript
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;
|
|
}
|
|
}
|
|
}
|