db.ts 490 B

123456789101112131415161718
  1. /**
  2. * Prisma client singleton for the dashboard.
  3. * Reads DATABASE_URL from environment.
  4. */
  5. import { PrismaClient } from '@prisma/client';
  6. const globalForPrisma = globalThis as unknown as { prisma: PrismaClient | undefined };
  7. export const prisma =
  8. globalForPrisma.prisma ??
  9. new PrismaClient({
  10. log: process.env['LOG_LEVEL'] === 'debug' ? ['query', 'warn', 'error'] : ['warn', 'error'],
  11. });
  12. if (process.env['NODE_ENV'] !== 'production') {
  13. globalForPrisma.prisma = prisma;
  14. }