Created
January 8, 2022 17:28
-
-
Save dipeshhkc/cb9fcaf76b8aa967e8c872e84b9e99f3 to your computer and use it in GitHub Desktop.
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"; | |
let db: PrismaClient; | |
declare global { | |
var __db: PrismaClient | undefined; | |
} | |
// this is needed because in development we don't want to restart | |
// the server with every change, but we want to make sure we don't | |
// create a new connection to the DB with every change either. | |
if (process.env.NODE_ENV === "production") { | |
db = new PrismaClient(); | |
db.$connect(); | |
} else { | |
if (!global.__db) { | |
global.__db = new PrismaClient(); | |
global.__db.$connect(); | |
} | |
db = global.__db; | |
} | |
export { db }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment