mirror of
https://github.com/p-stream/backend.git
synced 2026-03-17 00:06:47 +00:00
26 lines
718 B
TypeScript
26 lines
718 B
TypeScript
import { Pool } from 'pg';
|
|
import { PrismaPg } from '@prisma/adapter-pg';
|
|
import { PrismaClient } from '../../generated/client';
|
|
|
|
const globalForPrisma = globalThis as unknown as {
|
|
prisma: PrismaClient | undefined;
|
|
pool: Pool | undefined;
|
|
};
|
|
|
|
const pool =
|
|
globalForPrisma.pool ||
|
|
new Pool({
|
|
connectionString: process.env.DATABASE_URL,
|
|
max: Math.max(1, parseInt(process.env.DB_POOL_MAX, 10) || 30),
|
|
connectionTimeoutMillis: 10000,
|
|
idleTimeoutMillis: 300000,
|
|
});
|
|
|
|
const adapter = new PrismaPg(pool);
|
|
|
|
export const prisma = globalForPrisma.prisma || new PrismaClient({ adapter });
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
globalForPrisma.prisma = prisma;
|
|
globalForPrisma.pool = pool;
|
|
}
|