@rnaga/wp-node
Version:
👉 **[View Full Documentation at rnaga.github.io/wp-node →](https://rnaga.github.io/wp-node/)**
65 lines (64 loc) • 2.33 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var Alias_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Alias = void 0;
const constants_1 = require("../constants");
const tables_1 = require("../core/tables");
const component_1 = require("../decorators/component");
let Alias = class Alias {
static { Alias_1 = this; }
tables;
static count = 0;
#index;
constructor(tables) {
this.tables = tables;
this.#index = Alias_1.count++;
this.get = this.get.bind(this);
this.as = this.as.bind(this);
this.column = this.column.bind(this);
}
cloneIndex(alias) {
alias.#index = this.#index;
}
guess(table) {
if (constants_1.TABLE_NAMES.includes(table)) {
return this.tables.get(table);
}
return table;
}
get(key) {
const table = this.guess(key);
return {
table,
key: `${key}_${this.#index}`,
};
}
as(key, alias) {
const { table, key: keyIndex } = this.get(key);
if (alias) {
return `${table} as ${keyIndex}_${alias}`;
}
return `${table} as ${keyIndex}`;
}
column(key, col, alias) {
const { key: keyIndex } = this.get(key);
if (alias) {
return `${keyIndex}_${alias}.${col}`;
}
return `${keyIndex}.${col}`;
}
};
exports.Alias = Alias;
exports.Alias = Alias = Alias_1 = __decorate([
(0, component_1.component)({ scope: constants_1.Scope.Transient }),
__metadata("design:paramtypes", [tables_1.Tables])
], Alias);