Next.js full-stack analytics dashboard for new-api. - Direct PostgreSQL readonly queries on logs table - 5 pages: Dashboard, Rankings, Aggregation, Logs, Detail - Dark/Light/System theme with CSS variables - Chinese/English i18n (default Chinese) - Recharts with dual Y-axis for input/output tokens - Lucide icons + Motion animations - Docker + docker-compose with external sinobridge network, port 8019
19 lines
451 B
TypeScript
19 lines
451 B
TypeScript
import { Pool, type QueryResultRow } from "pg";
|
|
|
|
const pool = new Pool({
|
|
connectionString: process.env.PG_CONNECTION_STRING,
|
|
max: 10,
|
|
idleTimeoutMillis: 30000,
|
|
connectionTimeoutMillis: 5000,
|
|
});
|
|
|
|
export async function query<T extends QueryResultRow = QueryResultRow>(
|
|
text: string,
|
|
params?: (string | number | boolean | null)[]
|
|
): Promise<T[]> {
|
|
const { rows } = await pool.query<T>(text, params);
|
|
return rows;
|
|
}
|
|
|
|
export default pool;
|