Created
January 9, 2024 11:34
-
-
Save ahsanzizan/42aa2fa121257a01241ee31717da4eb5 to your computer and use it in GitHub Desktop.
Ensure prisma client only instantiated once
This file contains 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
import { PrismaClient } from '@prisma/client'; | |
declare global { | |
interface CustomNodeJsGlobal extends NodeJS.Global { | |
prisma: PrismaClient; | |
} | |
} | |
const prisma: PrismaClient = global.prisma ?? new PrismaClient(); | |
if (process.env.NODE_ENV === 'production') global.prisma = prisma; | |
export default prisma; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment