Open History to see the last commit
1import "server-only";
2import { Pool } from "pg";
3import { drizzle } from "drizzle-orm/node-postgres";
4import { attachDatabasePool } from "@vercel/functions";
5let pool: Pool | undefined;
6export function database() {
7 if (!process.env.DATABASE_URL) throw new Error("DATABASE_URL is missing");
8 if (!pool) {
9 pool = new Pool({
10 connectionString: process.env.DATABASE_URL,
11 max: 4,
12 connectionTimeoutMillis: 10000,
13 });
14 attachDatabasePool(pool);
15 }
16 return drizzle(pool);
17}
18export function databasePool() {
19 database();
20 return pool!;
21}