Skip to content

Commit 2d65965

Browse files
fix: 🐛 Add global prisma client
1 parent d59d489 commit 2d65965

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/database/prismaClient.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
import { PrismaClient } from '@prisma/client'
1+
import { PrismaClient } from '@prisma/client';
22

3-
const prisma = new PrismaClient();
3+
let prisma: PrismaClient;
4+
5+
if (process.env.NODE_ENV === 'production') {
6+
prisma = new PrismaClient();
7+
} else {
8+
const globalAny: any = global;
9+
if (!globalAny.prisma) {
10+
globalAny.prisma = new PrismaClient();
11+
}
12+
prisma = globalAny.prisma;
13+
}
414

515
export default prisma;

0 commit comments

Comments
 (0)