Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions lib/prisma.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();
export default prisma;
let prisma

if ( process.env.NODE_ENV === "production" ) {
// spin-up a Prisma client always on the production copy.
prisma = new PrismaClient()

} else {
// to prevent Prisma spinning-up too many clients in a development environment, check to see if one is already running
if (!global.prisma) {
global.prisma = new PrismaClient()
}

prisma = global.prisma
}

export default prisma