You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
490 B
TypeScript
16 lines
490 B
TypeScript
import { PrismaClient } from "@prisma/client"
|
|
import { PrismaPg } from "@prisma/adapter-pg"
|
|
import pg from "pg"
|
|
|
|
const globalForPrisma = globalThis as unknown as { prisma: PrismaClient | undefined }
|
|
|
|
const connectionString = process.env.DATABASE_URL
|
|
|
|
const pool = new pg.Pool({ connectionString })
|
|
const adapter = new PrismaPg(pool)
|
|
|
|
export const prisma =
|
|
globalForPrisma.prisma ?? new PrismaClient({ adapter })
|
|
|
|
if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma
|