Skip to content

Instantly share code, notes, and snippets.

@ardhptr21
Created March 22, 2023 15:07
Show Gist options
  • Save ardhptr21/d1319c0cbbd4afadaee59b825aca4c53 to your computer and use it in GitHub Desktop.
Save ardhptr21/d1319c0cbbd4afadaee59b825aca4c53 to your computer and use it in GitHub Desktop.
This script will ensure that only one instance of Prisma client exists
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