q1340 commited on
Commit
1a2e132
·
verified ·
1 Parent(s): 355e96e

Create src/db.ts

Browse files
Files changed (1) hide show
  1. src/db.ts +18 -0
src/db.ts ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // src/db.ts
2
+ import { Pool, neonConfig } from '@neondatabase/serverless';
3
+ import { PrismaNeon } from '@prisma/adapter-neon';
4
+ import { PrismaClient } from '@prisma/client';
5
+ import ws from 'ws';
6
+
7
+ // 配置 WebSocket 连接,让 Neon 驱动使用 WebSocket 与数据库通信[8†L17]。
8
+ neonConfig.webSocketConstructor = ws;
9
+
10
+ const connectionString = `${process.env.DATABASE_URL}`;
11
+
12
+ // 创建一个连接池
13
+ const pool = new Pool({ connectionString });
14
+
15
+ // 使用 Neon 适配器创建 Prisma 客户端实例
16
+ const adapter = new PrismaNeon(pool);
17
+
18
+ export const prisma = new PrismaClient({ adapter });