datewise/app/db.server.ts
metatroncubeswdev e56182e0e3 chore: initial Datewise app (rebranded from SlotSure prototype)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 20:06:49 -04:00

33 lines
975 B
TypeScript

import { PrismaClient } from "@prisma/client";
import { PrismaPg } from "@prisma/adapter-pg";
declare global {
// eslint-disable-next-line no-var
var prismaGlobal: PrismaClient | undefined;
}
/**
* Rust-free Prisma client over node-postgres (no native engine binary needed,
* which also makes shared/VPS hosting simpler).
*/
export function createPrisma(url = process.env.DATABASE_URL) {
if (!url) throw new Error("DATABASE_URL is not set");
return new PrismaClient({ adapter: new PrismaPg({ connectionString: url }) });
}
function instance(): PrismaClient {
if (!global.prismaGlobal) global.prismaGlobal = createPrisma();
return global.prismaGlobal;
}
/** Lazily created so importing this module never needs DATABASE_URL (tests, build). */
const prisma = new Proxy({} as PrismaClient, {
get(_t, prop) {
const db = instance();
const v = Reflect.get(db, prop);
return typeof v === "function" ? v.bind(db) : v;
},
});
export default prisma;