Skip to content

Instantly share code, notes, and snippets.

@tech-shamp
Last active August 30, 2023 07:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tech-shamp/915537adf2c8b0744e17a2e24e24c5e9 to your computer and use it in GitHub Desktop.
Save tech-shamp/915537adf2c8b0744e17a2e24e24c5e9 to your computer and use it in GitHub Desktop.
Prisma Client Declaration
import { PrismaClient } from "@prisma/client"
let prisma: PrismaClient
declare global {
namespace NodeJS {
interface Global {
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