refactor: repartition server-side and client-side code

This commit is contained in:
LIlGG
2025-10-11 18:26:07 +08:00
parent 7acc4949fb
commit e9b573a276
309 changed files with 631 additions and 962 deletions

View File

@@ -0,0 +1,28 @@
import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3';
import { PrismaClient } from '@prisma/client';
// 创建PrismaClient实例
let prisma: PrismaClient;
declare global {
var __db: PrismaClient | undefined;
}
const adapter = new PrismaBetterSQLite3({
url: 'file:data/upage.db',
});
// 在开发环境中使用全局变量,避免热重载时创建多个实例
if (process.env.NODE_ENV === 'production') {
prisma = new PrismaClient({ adapter });
} else {
if (!global.__db) {
global.__db = new PrismaClient({
log: ['query', 'error', 'warn'],
adapter,
});
}
prisma = global.__db;
}
export { prisma };