Skip to content

Instantly share code, notes, and snippets.

@raynirola
Created July 12, 2022 23:33
Show Gist options
  • Save raynirola/bba09f926f7e2978c17c60ea575201e5 to your computer and use it in GitHub Desktop.
Save raynirola/bba09f926f7e2978c17c60ea575201e5 to your computer and use it in GitHub Desktop.
Instantiating Prisma with NextJS using TypeScript
import { PrismaClient } from '@prisma/client'
const globalWithPrisma = global as typeof globalThis & { prisma: PrismaClient }
let prisma: PrismaClient
if (process.env.NODE_ENV === 'production') {
prisma = new PrismaClient()
} else {
if (!globalWithPrisma.prisma) globalWithPrisma.prisma = new PrismaClient()
prisma = globalWithPrisma.prisma
}
export default prisma
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment