Created
July 12, 2022 23:33
-
-
Save raynirola/bba09f926f7e2978c17c60ea575201e5 to your computer and use it in GitHub Desktop.
Instantiating Prisma with NextJS using TypeScript
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' | |
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