21 lines
592 B
TypeScript
21 lines
592 B
TypeScript
import { PrismaClient } from "@/app/generated/prisma/client";
|
|
import { PrismaPg } from "@prisma/adapter-pg";
|
|
import { Pool } from "pg";
|
|
|
|
const globalForPrisma = globalThis as unknown as {
|
|
prisma: PrismaClient | undefined;
|
|
pool: Pool | undefined;
|
|
};
|
|
|
|
const pool = globalForPrisma.pool ?? new Pool({
|
|
connectionString: process.env.DATABASE_URL,
|
|
});
|
|
|
|
const adapter = new PrismaPg(pool);
|
|
|
|
export const prisma = globalForPrisma.prisma ?? new PrismaClient({ adapter });
|
|
|
|
if (process.env.NODE_ENV !== "production") {
|
|
globalForPrisma.prisma = prisma;
|
|
globalForPrisma.pool = pool;
|
|
} |