Created
March 10, 2022 08:08
-
-
Save aindong/bb2fa5e1ba7bc8557ddd956341177abf to your computer and use it in GitHub Desktop.
Importing Prisma Best Practice on Nodejs + Express
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
import { PrismaClient } from '@prisma/client'; | |
declare global { | |
// allow global `var` declarations | |
// eslint-disable-next-line no-var | |
var prisma: PrismaClient | undefined; | |
} | |
export const prisma = | |
global.prisma || | |
new PrismaClient({ | |
log: ['query'] | |
}); | |
if (process.env.NODE_ENV !== 'production') global.prisma = prisma; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment