24 lines
683 B
TypeScript
24 lines
683 B
TypeScript
|
|
// services/api/src/prisma/prisma.service.ts —— @photo/db-cn 的可注入封装。
|
|||
|
|
// 连接池上限由 DATABASE_URL_CN 的 ?connection_limit=10 承担,这里不另行放大;
|
|||
|
|
// 不使用 enableShutdownHooks(Nest 10 经 onModuleDestroy 生命周期即可优雅断开)。
|
|||
|
|
import {
|
|||
|
|
Injectable,
|
|||
|
|
type OnModuleDestroy,
|
|||
|
|
type OnModuleInit,
|
|||
|
|
} from '@nestjs/common';
|
|||
|
|
import { PrismaClient } from '@photo/db-cn';
|
|||
|
|
|
|||
|
|
@Injectable()
|
|||
|
|
export class PrismaService
|
|||
|
|
extends PrismaClient
|
|||
|
|
implements OnModuleInit, OnModuleDestroy
|
|||
|
|
{
|
|||
|
|
async onModuleInit(): Promise<void> {
|
|||
|
|
await this.$connect();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
async onModuleDestroy(): Promise<void> {
|
|||
|
|
await this.$disconnect();
|
|||
|
|
}
|
|||
|
|
}
|