import pg from "pg"

// NOTE: This helper imports the generated Prisma client from TypeScript files.
// Run scripts that rely on it via a transpiling runner (e.g. `tsx` or Bun).
import { PrismaClient } from "../../src/generated/prisma/client.ts"
import { PrismaPg } from "@prisma/adapter-pg"

const { Pool } = pg

export function createPrismaClient() {
  const databaseUrl = process.env.DATABASE_URL

  if (!databaseUrl) {
    throw new Error("DATABASE_URL environment variable is required")
  }

  const pool = new Pool({
    connectionString: databaseUrl,
  })

  const adapter = new PrismaPg(pool)

  return new PrismaClient({ adapter })
}
