import { PrismaPg } from "@prisma/adapter-pg";
import { PrismaClient } from "./generated/prisma/client";
import fs from "node:fs";

const env = fs.readFileSync(".env", "utf8");
const line = env.split(/\n/).find((l) => l.startsWith("DATABASE_URL="));
const url = line?.slice("DATABASE_URL=".length)?.replace(/^"|"$/g, "");

const prisma = new PrismaClient({
  adapter: new PrismaPg({ connectionString: url }),
});

const rows = await prisma.$queryRaw`select tablename from pg_tables where schemaname = 'public' order by tablename`;
console.log(rows);
await prisma.$disconnect();
