Initial commit
This commit is contained in:
37
src/utils/sqlUtils.ts
Normal file
37
src/utils/sqlUtils.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
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;
|
||||
};
|
||||
Reference in New Issue
Block a user