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>
40 lines
1.1 KiB
JavaScript
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 };
|