2026-04-11 15:50:44 +02:00
|
|
|
import { Pool } from "pg";
|
|
|
|
|
import { PrismaPg } from "@prisma/adapter-pg";
|
2026-04-10 15:43:07 +02:00
|
|
|
import { PrismaClient } from "./generated/prisma/client";
|
|
|
|
|
|
|
|
|
|
const globalForPrisma = globalThis as unknown as { prisma?: PrismaClient };
|
|
|
|
|
|
|
|
|
|
function createPrisma() {
|
2026-04-11 15:50:44 +02:00
|
|
|
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
|
|
|
|
const adapter = new PrismaPg(pool);
|
2026-04-10 15:43:07 +02:00
|
|
|
return new PrismaClient({ adapter });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const prisma = globalForPrisma.prisma ?? createPrisma();
|
|
|
|
|
|
|
|
|
|
if (process.env.NODE_ENV !== "production") {
|
|
|
|
|
globalForPrisma.prisma = prisma;
|
|
|
|
|
}
|