57 lines
No EOL
2 KiB
TypeScript
57 lines
No EOL
2 KiB
TypeScript
import { Attribute, DB, Table } from "./db.js"
|
|
import { Handler } from "./defaultHandler.js";
|
|
|
|
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);
|
|
}
|
|
getString(handler: Handler = this.table.dbLangDatabaseInstance.getHandler()) {
|
|
return this.table.serialize(handler) + "." + this.serialize(handler);
|
|
}
|
|
getStringFunc(handler: Handler) {
|
|
return this.table.serialize(handler) + "(" + this.serialize(handler) + ")";
|
|
}
|
|
toString(){
|
|
return this.table.dbLangTableName + "_" + this.name;
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
} |