37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
export const generateSQLAttribute = (type: string, length: number, scale: number): string => {
|
|
switch (type) {
|
|
case 'Number':
|
|
return `Num(${length}, ${scale})`;
|
|
case 'Date':
|
|
return 'Date';
|
|
default:
|
|
// For string type, if converting from number, account for decimal point and scale
|
|
const adjustedLength = scale > 0 ? length + scale + 1 : length;
|
|
return `Varchar(${adjustedLength})`;
|
|
}
|
|
};
|
|
|
|
export const generateSQLDefault = (type: string): string => {
|
|
switch (type) {
|
|
case 'Number':
|
|
return 'Not Null Default 0';
|
|
case 'Date':
|
|
return `Not Null Default '1980-01-01'`;
|
|
default:
|
|
return `CCSID 37 Not Null Default ' '`;
|
|
}
|
|
};
|
|
|
|
export const sanitizeColumnName = (name: string): string => {
|
|
return name.replace(/[^a-zA-Z0-9_]/g, '_').toUpperCase();
|
|
};
|
|
|
|
export const getExcelColumn = (index: number): string => {
|
|
let column = '';
|
|
let num = index;
|
|
while (num >= 0) {
|
|
column = String.fromCharCode(65 + (num % 26)) + column;
|
|
num = Math.floor(num / 26) - 1;
|
|
}
|
|
return column;
|
|
};
|