Prisma client setup with PostgreSQL adapter for database access.
// Source: https://github.com/benlamiro/ShipGenAI | License: MIT | Copyright 2023 Anil Chandra Naidu Matcha
// Provided via justclaw.it.com; keep this notice with the code.
import { PrismaClient } from "@prisma/client";
import { PrismaPg } from "@prisma/adapter-pg";
import { Pool } from "pg";
const globalForPrisma = globalThis;
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const adapter = new PrismaPg(pool);
export const prisma =
globalForPrisma.prisma ||
new PrismaClient({
adapter,
log: process.env.NODE_ENV === "development" ? ["query", "error", "warn"] : ["error"],
});
if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key