import pg from 'pg'; // bigint (int8) columns hold Minecraft counters; they stay far below 2^53, so parse as number. pg.types.setTypeParser(20, (v) => Number(v)); // numeric is used for aggregates (SUM over bigint) pg.types.setTypeParser(1700, (v) => Number(v)); export type Pool = pg.Pool; export type PoolClient = pg.PoolClient; export function createPool(url: string, max = 10): pg.Pool { return new pg.Pool({ connectionString: url, max }); } export async function withTx(pool: pg.Pool, fn: (c: pg.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').catch(() => {}); throw err; } finally { client.release(); } }