import { Attribute, DB, Table } from "./db" import { Handler } from "./defaultHandler"; export class AttributeAlias { name: string; nameO: string; table: TableAlias; attr: Attribute; constructor(attr: Attribute, table: TableAlias) { this.name = attr.name; this.nameO = attr.nameO; this.attr = attr; this.table = table; } serialize(handler: Handler) { return handler.builders.escapeID(this.name); } toString(handler: Handler = this.table.dbLangDatabaseInstance.getHandler()) { return this.table.serialize(handler) + "." + this.serialize(handler); } toStringFunc(handler: Handler) { return this.table.serialize(handler) + "(" + this.serialize(handler) + ")"; } } export class TableAlias { dbLangTableName: string; dbLangTableAttributes: { [key: string]: AttributeAlias; } = {}; dbLangDatabaseInstance: DB; dbLangTableInstance: Table; [key: string]: AttributeAlias | any; constructor(name: string, table: Table) { this.dbLangTableName = name; this.dbLangTableInstance = table; this.dbLangDatabaseInstance = table.dbLangDatabaseInstance; let keys = Object.keys(table.dbLangTableAttributes); for (let i = 0; i < keys.length; i++) { const a = table.dbLangTableAttributes[keys[i]]; let attrAlias = new AttributeAlias(a, this); this[a.name] = attrAlias; this[a.nameO] = attrAlias; this.dbLangTableAttributes[a.name] = attrAlias; } } serializeAlias(hander: Handler) { return this.dbLangTableInstance.serialize(hander) + " " + this.toString(hander); } serialize(handler: Handler) { return this.toString(handler); } toString(handler: Handler = this.dbLangDatabaseInstance.getHandler()) { return handler.builders.escapeID(this.dbLangTableName); } }