Skip to content

Instantly share code, notes, and snippets.

@Deri-Kurniawan
Last active January 18, 2024 22:42
Show Gist options
  • Save Deri-Kurniawan/ac6b67440c60e34d2d48473d37d9a33f to your computer and use it in GitHub Desktop.
Save Deri-Kurniawan/ac6b67440c60e34d2d48473d37d9a33f to your computer and use it in GitHub Desktop.
import { PrismaClient } from "@prisma/client";
declare global {
var prisma: PrismaClient | undefined;
}
let prisma: PrismaClient;
if (process.env.NODE_ENV === "production") {
prisma = new PrismaClient();
} else {
if (!global.prisma) {
global.prisma = new PrismaClient();
}
prisma = global.prisma;
}
export default prisma;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment