import { PrismaClient } from '@prisma/client' import { Pool } from 'pg' import { PrismaPg } from '@prisma/adapter-pg' let client: PrismaClient | null = null function createClient(): PrismaClient { const url = process.env.DATABASE_URL if (!url) { throw new Error('DATABASE_URL is not set — see .env.example') } const pool = new Pool({ connectionString: url }) const adapter = new PrismaPg(pool) return new PrismaClient({ adapter, log: ['error'] }) } export const prisma = new Proxy({} as PrismaClient, { get(_target, prop) { if (!client) client = createClient() return Reflect.get(client, prop, client) }, })