25 lines
626 B
TypeScript
25 lines
626 B
TypeScript
import { PrismaPg } from "@prisma/adapter-pg";
|
|
import { PrismaClient } from "@prisma/client";
|
|
|
|
const globalForPrisma = globalThis as unknown as {
|
|
prisma: PrismaClient | undefined;
|
|
};
|
|
|
|
const connectionString = process.env.DATABASE_URL;
|
|
|
|
if (!connectionString) {
|
|
throw new Error("DATABASE_URL is not configured.");
|
|
}
|
|
|
|
const adapter = new PrismaPg({ connectionString });
|
|
|
|
export const prisma =
|
|
globalForPrisma.prisma ??
|
|
new PrismaClient({
|
|
adapter,
|
|
log: process.env.NODE_ENV === "development" ? ["warn", "error"] : ["error"],
|
|
});
|
|
|
|
if (process.env.NODE_ENV !== "production") {
|
|
globalForPrisma.prisma = prisma;
|
|
} |