File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { PrismaPg } from "@prisma/adapter-pg" ;
22import { PrismaClient } from "../generated/prisma/client" ;
3+ import { Pool } from "pg" ;
34export * from "../generated/prisma/client" ;
45
5- const adapter = new PrismaPg ( {
6- connectionString : process . env . DATABASE_URL ,
7- } ) ;
6+ const globalForPrisma = globalThis as unknown as {
7+ prisma ?: PrismaClient ;
8+ pgPool ?: Pool ;
9+ } ;
10+
11+ const pool =
12+ globalForPrisma . pgPool ??
13+ new Pool ( {
14+ connectionString : process . env . DATABASE_URL ,
15+ } ) ;
16+
17+ const adapter = new PrismaPg ( pool ) ;
18+
19+ export const prisma =
20+ globalForPrisma . prisma ??
21+ new PrismaClient ( {
22+ adapter,
23+ log :
24+ process . env . NODE_ENV === "development"
25+ ? [ "query" , "error" , "warn" ]
26+ : [ "error" ] ,
27+ } ) ;
28+
29+ if ( process . env . NODE_ENV !== "production" ) {
30+ globalForPrisma . prisma = prisma ;
31+ globalForPrisma . pgPool = pool ;
32+ }
833
9- const prisma = new PrismaClient ( { adapter } ) ;
1034
1135export default prisma ;
You can’t perform that action at this time.
0 commit comments