fix: Global BigInt conversion in postgres module

- Added convertBigInt helper in db/postgres.ts
- Converts all BigInt values to Number in query results
- Simplified admin.ts routes (removed workarounds)
- All APIs now work correctly
This commit is contained in:
2026-03-12 20:22:13 +00:00
parent bca4e18f8d
commit c0c129ea37
2 changed files with 146 additions and 203 deletions

View File

@@ -5,6 +5,22 @@ const DATABASE_URL = Deno.env.get("DATABASE_URL") ||
let pool: Pool;
// Convert BigInt to Number recursively in query results
function convertBigInt<T>(obj: T): T {
if (obj === null || obj === undefined) return obj;
if (typeof obj === 'bigint') return Number(obj) as unknown as T;
if (obj instanceof Date) return obj;
if (Array.isArray(obj)) return obj.map(convertBigInt) as unknown as T;
if (typeof obj === 'object') {
const result: Record<string, unknown> = {};
for (const [key, value] of Object.entries(obj as Record<string, unknown>)) {
result[key] = convertBigInt(value);
}
return result as T;
}
return obj;
}
export async function initDB(): Promise<void> {
pool = new Pool(DATABASE_URL, 10);
@@ -29,7 +45,8 @@ export async function query<T>(sql: string, params?: unknown[]): Promise<T[]> {
text: sql,
args: params || [],
});
return result.rows;
// Convert BigInt to Number in all results
return result.rows.map(row => convertBigInt(row));
} finally {
client.release();
}
@@ -47,7 +64,7 @@ export async function execute(sql: string, params?: unknown[]): Promise<number>
text: sql,
args: params || [],
});
return result.rowCount || 0;
return Number(result.rowCount || 0);
} finally {
client.release();
}