17 lines
656 B
TypeScript
17 lines
656 B
TypeScript
import { PrismaClient } from "@/lib/generated/prisma/client";
|
|
import { PrismaPg } from "@prisma/adapter-pg";
|
|
|
|
// Prisma 7 requires an explicit driver adapter for SQL providers.
|
|
const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL });
|
|
|
|
// Reuse a single PrismaClient across hot-reloads in dev (Next.js clears the
|
|
// module cache on most edits, which would otherwise open a new pool per reload).
|
|
const globalForPrisma = globalThis as unknown as { prisma?: PrismaClient };
|
|
|
|
export const prisma =
|
|
globalForPrisma.prisma ?? new PrismaClient({ adapter });
|
|
|
|
if (process.env.NODE_ENV !== "production") {
|
|
globalForPrisma.prisma = prisma;
|
|
}
|