Something went wrong. Try again.
An atproto indexer and web app that scrapes domains from collections it sees
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940import pg from "pg";
const { Pool } = pg;
// Module-level singleton - shared for the lifetime of the server processlet _pool: pg.Pool | null = null;
function getPool(): pg.Pool { if (_pool) return _pool;
const connectionString = process.env.DATABASE_URL; if (!connectionString) { throw new Error("DATABASE_URL environment variable is required"); }
_pool = new Pool({ connectionString, ssl: process.env.DATABASE_SSL === "true" ? { rejectUnauthorized: false } : false, max: 5, idleTimeoutMillis: 30_000, connectionTimeoutMillis: 5_000, });
_pool.on("error", (err) => { console.error("[db] Pool error:", err.message); });
return _pool;}
export async function query<T extends pg.QueryResultRow = pg.QueryResultRow>( sql: string, params: (string | number | null | boolean | string[])[] = []): Promise<pg.QueryResult<T>> { return getPool().query<T>(sql, params);}