UNPKG

tspace-mysql

Version:

Tspace MySQL is a promise-based ORM for Node.js, designed with modern TypeScript and providing type safety for schema databases.

50 lines 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Join = void 0; class Join { self; type; join = []; constructor(self, type = 'INNER_JOIN') { this.self = self; this.type = type; } on(localKey, referenceKey) { const table = referenceKey?.split('.')?.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