lib/db.ts

crawlseo · lib/db.ts · typescript · MIT
database

Module exposing: db

// Source: https://github.com/crawlseo/crawlseo | License: MIT | Copyright 2026 crawlseo
// 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 db =
  globalForPrisma.prisma ||
  new PrismaClient({
    log:
      process.env.NODE_ENV === "development"
        ? ["error", "warn"]
        : ["error"],
  });

if (process.env.NODE_ENV !== "production") {
  globalForPrisma.prisma = db;
}

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key