Spaces:
Configuration error
Configuration error
| import { Pool } from 'pg' | |
| import { PrismaPg } from '@prisma/adapter-pg' | |
| import { PrismaClient } from '@prisma/client' | |
| const globalForPrisma = globalThis as unknown as { | |
| prisma: PrismaClient | undefined | |
| } | |
| function createPrismaClient() { | |
| const connectionString = process.env.DATABASE_URL | |
| if (!connectionString) { | |
| console.error('DATABASE_URL is not set. Value:', connectionString) | |
| throw new Error('DATABASE_URL environment variable is not set') | |
| } | |
| const pool = new Pool({ | |
| connectionString, | |
| max: 10, // Maximum connections in the pool | |
| idleTimeoutMillis: 30000, // Close idle connections after 30s | |
| connectionTimeoutMillis: 10000, // Fail if connection takes > 10s | |
| }) | |
| const adapter = new PrismaPg(pool) | |
| return new PrismaClient({ adapter }) | |
| } | |
| export const prisma = globalForPrisma.prisma ?? createPrismaClient() | |
| if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma | |
| export default prisma | |