import "server-only"; import type { PoolClient, QueryResultRow } from "pg"; import { pool } from "./pool"; export async function query( text: string, params?: unknown[] ): Promise { const result = await pool.query(text, params); return result.rows; } export async function queryOne( text: string, params?: unknown[] ): Promise { const rows = await query(text, params); return rows[0] ?? null; } export async function withTransaction( fn: (client: PoolClient) => Promise ): Promise { const client = await pool.connect(); try { await client.query("begin"); const result = await fn(client); await client.query("commit"); return result; } catch (err) { await client.query("rollback"); throw err; } finally { client.release(); } }