tspace-mysql
Version:
Tspace MySQL is a promise-based ORM for Node.js, designed with modern TypeScript and providing type safety for schema databases.
49 lines • 1.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Join = void 0;
class Join {
constructor(self, type = 'INNER_JOIN') {
this.self = self;
this.type = type;
this.join = [];
}
on(localKey, referenceKey) {
var _a;
const table = (_a = referenceKey === null || referenceKey === void 0 ? void 0 : referenceKey.split('.')) === null || _a === void 0 ? void 0 : _a.shift();
const join = [
`${this.self['$constants'](this.type)}`,
`\`${table}\` ${this.self['$constants']('ON')}`,
`${this.self.bindColumn(localKey)} = ${this.self.bindColumn(String(referenceKey))}`
].join(' ');
this.join.push(join);
return this;
}
and(localKey, referenceKey) {
if (!this.join.length) {
return this.on(localKey, referenceKey);
}
const join = [
`${this.self['$constants']('AND')}`,
`${this.self.bindColumn(localKey)} = ${this.self.bindColumn(String(referenceKey))}`
].join(' ');
this.join.push(join);
return this;
}
or(localKey, referenceKey) {
if (!this.join.length) {
return this.on(localKey, referenceKey);
}
const join = [
`${this.self['$constants']('OR')}`,
`${this.self.bindColumn(localKey)} = ${this.self.bindColumn(String(referenceKey))}`
].join(' ');
this.join.push(join);
return this;
}
toString() {
return this.join.join(' ');
}
}
exports.Join = Join;
exports.default = Join;
//# sourceMappingURL=Join.js.map