Skip to content

Commit 1a3a21d

Browse files
authored
instantiating PrismaClient
Based on the best practices outlined in the Prisma documentation, I discovered that the current method of instantiating the PrismaClient using the app directory could potentially lead to some issues. To ensure a more robust and reliable implementation, I recommend adopting this approach as outlined in official Prisma docs. You can read more about this in Prisma documentation: https://www.prisma.io/docs/guides/other/troubleshooting-orm/help-articles/nextjs-prisma-client-dev-practices
1 parent 7096c98 commit 1a3a21d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/lib/prisma.ts

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

3-
export const prisma = new PrismaClient();
3+
const globalForPrisma = globalThis as unknown as {
4+
prisma: PrismaClient | undefined
5+
}
6+
7+
export const prisma = globalForPrisma.prisma ?? new PrismaClient()
8+
9+
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma

0 commit comments

Comments
 (0)