pf_app/lib/utils.js
Paul Trowbridge 08dc415bfd Initial commit — pivot forecast application
Node.js/Express + PostgreSQL forecasting app with AG Grid Enterprise pivot UI.
Supports baseline, scale, recode, clone operations on configurable source tables.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-01 07:59:05 -04:00

40 lines
1.1 KiB
JavaScript

// derive forecast table name from source tname + version id
function fcTable(tname, versionId) {
return `pf.fc_${tname}_${versionId}`;
}
// map information_schema data_type to a clean postgres column type
function mapType(dataType, numericPrecision, numericScale) {
switch (dataType) {
case 'character varying':
case 'character':
case 'text':
return 'text';
case 'smallint':
case 'integer':
return 'integer';
case 'bigint':
return 'bigint';
case 'numeric':
case 'decimal':
return (numericPrecision)
? `numeric(${numericPrecision}, ${numericScale || 0})`
: 'numeric';
case 'real':
case 'double precision':
return 'numeric';
case 'date':
return 'date';
case 'timestamp without time zone':
return 'timestamp';
case 'timestamp with time zone':
return 'timestamptz';
case 'boolean':
return 'boolean';
default:
return 'text';
}
}
module.exports = { fcTable, mapType };