Created
March 22, 2023 15:07
-
-
Save ardhptr21/d1319c0cbbd4afadaee59b825aca4c53 to your computer and use it in GitHub Desktop.
This script will ensure that only one instance of Prisma client exists
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
import { PrismaClient } from '@prisma/client'; | |
declare global { | |
namespace NodeJS { | |
interface Global {} | |
} | |
} | |
interface CustomNodeJsGlobal extends NodeJS.Global { | |
prisma: PrismaClient; | |
} | |
declare const global: CustomNodeJsGlobal; | |
const prisma = 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