-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.ts
More file actions
28 lines (23 loc) · 712 Bytes
/
Copy pathclient.ts
File metadata and controls
28 lines (23 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import "server-only";
import { PrismaClient } from "@prisma/client";
declare global {
var prisma: PrismaClient | undefined;
}
export const db = globalThis.prisma || new PrismaClient({
log: process.env.NODE_ENV === "development"
? ["error", "warn"]
: ["error"],
errorFormat: "pretty",
});
if (typeof window === "undefined" && !process.env.DATABASE_URL) {
console.error(
"⚠️ DATABASE_URL environment variable is not set. " +
"Please set it in your environment variables (Vercel: Settings > Environment Variables)"
);
}
db.$on("error" as never, (e: any) => {
console.error("Prisma Client Error:", e);
});
if (process.env.NODE_ENV !== "production") {
globalThis.prisma = db;
}