lib/prisma.ts

WA-AKG · src/lib/prisma.ts · typescript · MIT
database, Database / ORM

Singleton Prisma client wrapper that reuses a global instance across environments.

// Source: https://github.com/mrifqidaffaaditya/WA-AKG | License: MIT | Copyright 2026 Aditya
// Provided via justclaw.it.com; keep this notice with the code.
import { PrismaClient } from "@prisma/client";

const globalForPrisma = global as unknown as { prisma: PrismaClient };

export const prisma =
  globalForPrisma.prisma ||
  new PrismaClient({
    log: ["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