feat: Integrar PostgreSQL en VPS para RecreoPay con soporte en pgAdmin y retener compatibilidad local

This commit is contained in:
unknown
2026-10-05 04:04:33 -06:00
parent 578feec17d
commit e3780034c2
6 changed files with 399 additions and 12 deletions
+35
View File
@@ -0,0 +1,35 @@
const { runAsWorker } = require('synckit');
const { Pool, types } = require('pg');
// Mapear tipos numéricos de PostgreSQL a Number en JavaScript
types.setTypeParser(20, (val) => val === null ? null : parseInt(val, 10)); // int8 / bigint
types.setTypeParser(21, (val) => val === null ? null : parseInt(val, 10)); // int2 / smallint
types.setTypeParser(23, (val) => val === null ? null : parseInt(val, 10)); // int4 / integer
types.setTypeParser(1700, (val) => val === null ? null : parseFloat(val)); // numeric / decimal
types.setTypeParser(700, (val) => val === null ? null : parseFloat(val)); // float4 / real
types.setTypeParser(701, (val) => val === null ? null : parseFloat(val)); // float8 / double precision
const connectionString = process.env.DATABASE_URL || 'postgresql://postgres:[email protected]:5432/recreopay_db';
const pool = new Pool({
connectionString,
max: 10,
idleTimeoutMillis: 30000,
connectionTimeoutMillis: 5000
});
pool.on('error', (err) => {
console.error('⚠️ Error en pool PostgreSQL:', err.message);
});
runAsWorker(async ({ sql, params }) => {
try {
const res = await pool.query(sql, params || []);
return {
rows: res.rows || [],
rowCount: res.rowCount || 0
};
} catch (err) {
throw new Error(err.message);
}
});