16 lines
428 B
TypeScript
16 lines
428 B
TypeScript
import "server-only";
|
|
import { drizzle } from "drizzle-orm/postgres-js";
|
|
import postgres from "postgres";
|
|
import * as schema from "./schema";
|
|
|
|
const globalForDb = globalThis as unknown as { pgClient: ReturnType<typeof postgres> };
|
|
|
|
if (!globalForDb.pgClient) {
|
|
globalForDb.pgClient = postgres(process.env.DATABASE_URL!, {
|
|
max: 5,
|
|
idle_timeout: 20,
|
|
});
|
|
}
|
|
|
|
export const db = drizzle(globalForDb.pgClient, { schema });
|