forked from Astrea-Payouts/astrea
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.ts
More file actions
23 lines (19 loc) · 894 Bytes
/
Copy pathdb.ts
File metadata and controls
23 lines (19 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { PrismaPg } from "@prisma/adapter-pg";
import { PrismaClient } from "@/generated/prisma/client";
// Runtime connection — pooled (DATABASE_URL), safe for serverless/edge fan-out.
// The Prisma CLI (migrate, studio) uses the direct connection instead, configured
// separately in prisma.config.ts, per Supabase's pooler + migrations constraint.
const globalForPrisma = globalThis as unknown as { prisma?: PrismaClient };
function createClient() {
const connectionString = process.env.DATABASE_URL;
if (!connectionString) {
throw new Error("DATABASE_URL is not set");
}
const adapter = new PrismaPg({ connectionString });
return new PrismaClient({ adapter });
}
// Reused across hot reloads in dev so we don't exhaust the connection pool.
export const db = globalForPrisma.prisma ?? createClient();
if (process.env.NODE_ENV !== "production") {
globalForPrisma.prisma = db;
}