pref: change the database type to SQLite

This commit is contained in:
LIlGG
2025-09-25 15:24:13 +08:00
parent 1f4fb103e9
commit 530dfac665
16 changed files with 513 additions and 311 deletions

View File

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