diff --git a/lib/prisma.ts b/lib/prisma.ts index 63f8bbd..bcdcc1b 100644 --- a/lib/prisma.ts +++ b/lib/prisma.ts @@ -1,4 +1,15 @@ import { PrismaClient } from "@prisma/client"; -const prisma = new PrismaClient(); +const prismaClientSingleton = () => { + return new PrismaClient(); +}; + +declare global { + var prisma: undefined | ReturnType; +} + +const prisma = globalThis.prisma ?? prismaClientSingleton(); + export default prisma; + +if (process.env.NODE_ENV !== "production") globalThis.prisma = prisma;