mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-04-26 23:48:27 -04:00
20 lines
765 B
TypeScript
20 lines
765 B
TypeScript
import { PrismaClient } from "@prisma/client/edge";
|
|
|
|
// creating PrismaClient here prevents next.js from starting too many concurrent prisma instances and exhausting the
|
|
// number of connection pools available (especially when hot reloading from `next dev`).
|
|
// https://www.prisma.io/docs/guides/other/troubleshooting-orm/help-articles/nextjs-prisma-client-dev-practices
|
|
|
|
const prismaClientSingleton = () => {
|
|
return new PrismaClient();
|
|
};
|
|
|
|
type PrismaClientSingleton = ReturnType<typeof prismaClientSingleton>;
|
|
|
|
const globalForPrisma = globalThis as unknown as {
|
|
prisma: PrismaClientSingleton | undefined;
|
|
};
|
|
|
|
export const prisma = globalForPrisma.prisma ?? prismaClientSingleton();
|
|
|
|
if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
|