File size: 546 Bytes
c61f54b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import { drizzle } from "drizzle-orm/node-postgres";
import { Pool } from "pg";
const databaseUrl = process.env.DATABASE_URL;
if (!databaseUrl) {
throw new Error("DATABASE_URL is required");
}
const globalForDb = globalThis as typeof globalThis & {
__arenaNextJsPostgresqlPool?: Pool;
};
export const pool =
globalForDb.__arenaNextJsPostgresqlPool ??
new Pool({
connectionString: databaseUrl,
});
if (process.env.NODE_ENV !== "production") {
globalForDb.__arenaNextJsPostgresqlPool = pool;
}
export const db = drizzle(pool); |