Performance: PostgreSQL connection with pg
MEDIUM IMPACT
This affects the initial page load speed and responsiveness by controlling how database queries impact server response time.
import { Pool } from 'pg'; const pool = new Pool({ connectionString: process.env.DATABASE_URL }); async function fetchData() { const res = await pool.query('SELECT * FROM users'); return res.rows; }
import { Client } from 'pg'; async function fetchData() { const client = new Client({ connectionString: process.env.DATABASE_URL }); await client.connect(); const res = await client.query('SELECT * FROM users'); await client.end(); return res.rows; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| New client per query | N/A | N/A | N/A | [X] Bad |
| Connection pool reuse | N/A | N/A | N/A | [OK] Good |