Last active
January 11, 2023 20:50
-
-
Save DanielHemmati/92e227b5a6fb7aead54735c7f3489263 to your computer and use it in GitHub Desktop.
prisma client for nextjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/prisma/prisma/discussions/10037 | |
// and why it does matter: https://www.prisma.io/docs/concepts/components/prisma-client/working-with-prismaclient/instantiate-prisma-client#the-number-of-prismaclient-instances-matters | |
import { PrismaClient } from "@prisma/client"; | |
let prisma: PrismaClient; | |
if (process.env.NODE_ENV === "production") { | |
prisma = new PrismaClient(); | |
} else { | |
let globalWithPrisma = global as typeof globalThis & { | |
prisma: PrismaClient; | |
}; | |
if (!globalWithPrisma.prisma) { | |
globalWithPrisma.prisma = new PrismaClient(); | |
} | |
prisma = globalWithPrisma.prisma; | |
// it seems like they change the code again | |
// https://www.prisma.io/docs/guides/database/troubleshooting-orm/help-articles/nextjs-prisma-client-dev-practices | |
} | |
export default prisma; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment