2023-02-18 14:47:44 +01:00
|
|
|
import { Attribute, DB, Table } from "./db"
|
|
|
|
import { Handler } from "./defaultHandler";
|
2023-02-18 11:45:23 +01:00
|
|
|
|
2023-02-18 14:47:44 +01:00
|
|
|
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);
|
|
|
|
}
|
2023-02-25 14:52:46 +01:00
|
|
|
getString(handler: Handler = this.table.dbLangDatabaseInstance.getHandler()) {
|
2023-02-18 14:47:44 +01:00
|
|
|
return this.table.serialize(handler) + "." + this.serialize(handler);
|
|
|
|
}
|
2023-02-25 14:52:46 +01:00
|
|
|
getStringFunc(handler: Handler) {
|
2023-02-18 14:47:44 +01:00
|
|
|
return this.table.serialize(handler) + "(" + this.serialize(handler) + ")";
|
|
|
|
}
|
2023-02-25 14:52:46 +01:00
|
|
|
toString(){
|
|
|
|
return this.table.dbLangTableName + "_" + this.name;
|
|
|
|
}
|
2023-02-18 11:45:23 +01:00
|
|
|
}
|
|
|
|
|
2023-02-18 14:47:44 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2023-02-18 15:06:31 +01:00
|
|
|
serializeAlias(hander: Handler) {
|
|
|
|
return this.dbLangTableInstance.serialize(hander) + " " + this.toString(hander);
|
|
|
|
}
|
2023-02-18 14:47:44 +01:00
|
|
|
serialize(handler: Handler) {
|
|
|
|
return this.toString(handler);
|
|
|
|
}
|
|
|
|
toString(handler: Handler = this.dbLangDatabaseInstance.getHandler()) {
|
|
|
|
return handler.builders.escapeID(this.dbLangTableName);
|
|
|
|
}
|
2023-02-18 11:45:23 +01:00
|
|
|
}
|