UNPKG

ddl-manager

Version:

store postgres procedures and triggers in files

79 lines 2.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.equalType = exports.formatType = exports.Type = void 0; class Type { constructor(value) { this.value = value; this.normalized = formatType(value); } isArray() { return /\[\]$/.test(this.value); } suit(newType) { if (this.normalized === "bigint" && newType.normalized === "integer") { return true; } return this.normalized === newType.normalized; } toString() { return this.value; } } exports.Type = Type; function formatType(someType) { if (!someType) { return null; } someType = someType.trim() .toLowerCase() .replace(/\s+/g, " ") .replace(/"/g, ""); if (someType.startsWith("numeric")) { return "numeric"; } if (someType === "float8") { return "double precision"; } if (someType === "float8[]") { return "double precision[]"; } if (someType === "timestamp") { return "timestamp without time zone"; } if (someType === "timestamp[]") { return "timestamp without time zone[]"; } if (someType === "int8") { return "bigint"; } if (someType === "int4") { return "integer"; } if (someType === "int2") { return "smallint"; } if (someType === "int8[]") { return "bigint[]"; } if (someType === "int4[]") { return "integer[]"; } if (someType === "int2[]") { return "smallint[]"; } if (someType === "bool") { return "boolean"; } return someType; } exports.formatType = formatType; function equalType(inputTypeA, inputTypeB) { const typeA = formatType(inputTypeA); const typeB = formatType(inputTypeB); return (typeA === typeB || typeA === "public." + typeB || "public." + typeA === typeB); } exports.equalType = equalType; //# sourceMappingURL=Type.js.map