quick-erd
Version:
quick and easy text-based ERD + code generator for migration, query, typescript types and orm entity
32 lines (31 loc) • 849 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.toTsType = toTsType;
function toTsType(type) {
if (type.match(/^n?varchar/i) ||
type.match(/^string/i) ||
type.match(/^text/i)) {
return 'string';
}
if (type.match(/^decimal/i) ||
type.match(/^numeric/i) ||
type.match(/^int/i) ||
type.match(/^float/i) ||
type.match(/^double/i) ||
type.match(/^real/i)) {
return 'number';
}
if (type.match(/^bool/i)) {
return 'boolean';
}
if (type.match(/^enum/i)) {
return type.replace(/^enum/i, '').split(',').join(' | ');
}
if (type.match(/^date/i) || type.match(/^time/i)) {
return 'string';
}
if (type.match(/^blob/i)) {
return 'Buffer';
}
return 'string // ' + type;
}
;