import { Pool } from 'pg'; import { drizzle } from 'drizzle-orm/node-postgres'; import * as schema from './schema'; // Reuse a single pool across Next.js HMR reloads and within the worker process. const globalForDb = globalThis as unknown as { __autoLmsPool?: Pool }; export const pool = globalForDb.__autoLmsPool ?? new Pool({ connectionString: process.env.DATABASE_URL, max: 10, }); if (!globalForDb.__autoLmsPool) { globalForDb.__autoLmsPool = pool; } export const db = drizzle(pool, { schema }); export type Db = typeof db;