🚀 核心更新: - ✅ 完善 NestJS 企业级架构设计 - ✅ 优化配置中心和基础设施层 - ✅ 增强第三方服务集成能力 - ✅ 完善多租户架构支持 - 🎯 对标 Java Spring Boot 和 PHP ThinkPHP 📦 新增文件: - wwjcloud-nest 完整框架结构 - Docker 容器化配置 - 管理后台界面 - 数据库迁移脚本 🔑 Key: ebb38b43ec39f355f071294fd1cf9c42
52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
import { Module, Global } from '@nestjs/common';
|
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
import { DatabaseBackupService } from './backup.service';
|
|
import { UtilsModule } from '../utils/utils.module';
|
|
|
|
/**
|
|
* 数据库模块 - 基础设施层
|
|
* 基于 NestJS 官方文档实现
|
|
* 参考: https://docs.nestjs.cn/techniques/database
|
|
* 对应 Java: MyBatis-Plus
|
|
*
|
|
* 职责:
|
|
* - TypeORM 配置和连接管理
|
|
* - 数据库备份和恢复服务
|
|
* - 数据库相关的工具服务
|
|
*/
|
|
@Global()
|
|
@Module({
|
|
imports: [
|
|
TypeOrmModule.forRootAsync({
|
|
imports: [ConfigModule],
|
|
inject: [ConfigService],
|
|
useFactory: (configService: ConfigService) => ({
|
|
type: 'mysql',
|
|
host: configService.get('database.host', 'localhost'),
|
|
port: configService.get('database.port', 3306),
|
|
username: configService.get('database.username', 'root'),
|
|
password: configService.get('database.password', 'root'),
|
|
database: configService.get('database.database', 'wwjcloud'),
|
|
entities: [
|
|
__dirname + '/../**/*.entity{.ts,.js}',
|
|
__dirname + '/../../config/**/*.entity{.ts,.js}',
|
|
],
|
|
synchronize: true, // 临时启用自动同步来创建表
|
|
logging: configService.get('database.logging', false),
|
|
timezone: '+08:00',
|
|
charset: 'utf8mb4',
|
|
extra: {
|
|
connectionLimit: 10,
|
|
acquireTimeout: 60000,
|
|
timeout: 60000,
|
|
},
|
|
}),
|
|
}),
|
|
UtilsModule,
|
|
],
|
|
providers: [DatabaseBackupService],
|
|
exports: [TypeOrmModule, DatabaseBackupService],
|
|
})
|
|
export class DatabaseModule {}
|