ddl-manager
Version:
store postgres procedures and triggers in files
40 lines • 1.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PGTypes = void 0;
class PGTypes {
constructor(db) {
this.db = db;
this.typeById = {};
this.loaded = false;
}
async load() {
if (this.loaded) {
return;
}
this.typeById = {};
const result = await this.db.query(`
select
typname,
oid,
typinput,
typelem
from pg_type
`);
result.rows.forEach(row => {
let type = row.typname;
const isArray = row.typinput === "array_in";
if (isArray) {
const elemType = result.rows.find(elemRow => elemRow.oid === row.typelem);
type = elemType.typname + "[]";
}
this.typeById[row.oid] = type;
});
this.loaded = true;
}
getTypeById(oid) {
const type = this.typeById[oid] || null;
return type;
}
}
exports.PGTypes = PGTypes;
//# sourceMappingURL=PGTypes.js.map