Created
May 21, 2023 13:03
-
-
Save guidani/c240f963b5a36c54504777c2dc23b24a to your computer and use it in GitHub Desktop.
Make prisma global typescript
This file contains 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
// lib/prisma.ts | |
import { PrismaClient } from '@prisma/client'; | |
let prisma: PrismaClient; | |
if (process.env.NODE_ENV === 'production') { | |
prisma = new PrismaClient(); | |
} else { | |
let globalWithPrisma = global as typeof globalThis & { | |
prisma: PrismaClient; | |
}; | |
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
Add a file global.d.ts