-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathclient.ts
More file actions
35 lines (28 loc) · 763 Bytes
/
client.ts
File metadata and controls
35 lines (28 loc) · 763 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
29
30
31
32
33
34
35
import { PrismaPg } from "@prisma/adapter-pg";
import { PrismaClient } from "../generated/prisma/client";
import { Pool } from "pg";
export * from "../generated/prisma/client";
const globalForPrisma = globalThis as unknown as {
prisma?: PrismaClient;
pgPool?: Pool;
};
const pool =
globalForPrisma.pgPool ??
new Pool({
connectionString: process.env.DATABASE_URL,
});
const adapter = new PrismaPg(pool);
export const prisma =
globalForPrisma.prisma ??
new PrismaClient({
adapter,
log:
process.env.NODE_ENV === "development"
? ["query", "error", "warn"]
: ["error"],
});
if (process.env.NODE_ENV !== "production") {
globalForPrisma.prisma = prisma;
globalForPrisma.pgPool = pool;
}
export default prisma;