feat(平台): 补齐服务端持久化和AI拆解契约
This commit is contained in:
@@ -1,13 +1,26 @@
|
||||
import { Injectable, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
|
||||
import { Injectable, Logger, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
@Injectable()
|
||||
export class PrismaService extends PrismaClient implements OnModuleInit, OnModuleDestroy {
|
||||
private readonly logger = new Logger(PrismaService.name);
|
||||
private connected = false;
|
||||
|
||||
async onModuleInit() {
|
||||
await this.$connect();
|
||||
try {
|
||||
await this.$connect();
|
||||
this.connected = true;
|
||||
this.logger.log('Prisma connected');
|
||||
} catch (e: any) {
|
||||
this.logger.warn(
|
||||
`数据库连接失败 (${e?.errorCode || e?.message || e}) — 跳过,需要 DB 的接口将不可用,但不影响 AI 配置 / 拆解模块`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async onModuleDestroy() {
|
||||
await this.$disconnect();
|
||||
if (this.connected) {
|
||||
await this.$disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user