UNPKG

ddl-manager

Version:

store postgres procedures and triggers in files

56 lines (47 loc) 1.29 kB
import { DEFAULT_SCHEMA } from "../../parser/defaults"; import { MAX_NAME_LENGTH } from "../postgres/constants"; const keywords = [ "order", "where", "from", "join", "on", "select" ]; export class TableID { static fromString(schemaTable: string) { const [schema, table] = schemaTable.split("."); if ( !table ) { return new TableID( DEFAULT_SCHEMA, schema ); } return new TableID(schema, table); } readonly schema: string; readonly name: string; constructor(schema: string, name: string) { this.schema = schema.replace(/"/g, ""); this.name = name.replace(/"/g, "").slice(0, MAX_NAME_LENGTH); } equal(otherTable: TableID) { return ( this.schema === otherTable.schema && this.name === otherTable.name ); } toString() { return `${this.schema}.${this.name}`; } // TODO: use it as default toString toStringWithoutPublic() { const nameIsKeyWord = keywords.includes(this.name); if ( !nameIsKeyWord && this.schema === "public" ) { return this.name; } else { return `${this.schema}.${this.name}`;; } } }