19 lines
448 B
TypeScript
19 lines
448 B
TypeScript
// lib/db.ts
|
|
import { drizzle } from "drizzle-orm/node-postgres";
|
|
import { Pool } from "pg";
|
|
|
|
// Fail fast if env is missing
|
|
if (!process.env.DATABASE_URL) {
|
|
throw new Error("DATABASE_URL is not set");
|
|
}
|
|
|
|
const pool = new Pool({
|
|
connectionString: process.env.DATABASE_URL,
|
|
ssl:
|
|
process.env.NODE_ENV === "production"
|
|
? { rejectUnauthorized: false }
|
|
: false,
|
|
});
|
|
|
|
// Export a single db instance
|
|
export const db = drizzle(pool);
|