database-builder
Version:
Library to assist in creating and maintaining SQL commands.
54 lines (53 loc) • 2.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProjectionCaseWhen = void 0;
var utils_1 = require("../core/utils");
var case_when_1 = require("./enums/case-when");
var builder_compiled_1 = require("../core/builder-compiled");
var projection_compile_1 = require("./projection-compile");
var ProjectionCaseWhen = /** @class */ (function () {
function ProjectionCaseWhen(value) {
this._whenBuilder = new builder_compiled_1.BuilderCompiled();
this._whenBuilder.builder = "WHEN ";
if (utils_1.Utils.isWhereBuilder(value)) {
var whereCompiled = value.compile();
this.build(whereCompiled.where, whereCompiled.params);
}
else {
this.build(value, []);
}
}
ProjectionCaseWhen.prototype.then = function (projection) {
return this.projection(case_when_1.CaseWhen.Then, projection);
};
ProjectionCaseWhen.prototype.else = function (projection) {
return this.projection(case_when_1.CaseWhen.Else, projection);
};
// WHEN {expression} THEN {result} [ELSE {result}]
ProjectionCaseWhen.prototype.compile = function () {
return this._whenBuilder;
};
ProjectionCaseWhen.prototype.build = function (value, params) {
this._whenBuilder.builder += utils_1.Utils.getValueType(value);
this._whenBuilder.params = this._whenBuilder.params.concat(params);
};
ProjectionCaseWhen.prototype.projection = function (type, projection) {
if (utils_1.Utils.isProjectionsHelper(projection)) {
var projectionCompiled = projection_compile_1.ProjectionCompile.compile(projection._result());
this._whenBuilder.builder += " ".concat(type, " ").concat(projectionCompiled.projection);
this._whenBuilder.params = this._whenBuilder.params.concat(projectionCompiled.params);
}
else if (utils_1.Utils.isProjectionBuilder(projection)) {
var projectionCompiled = projection_compile_1.ProjectionCompile.compile(projection.result());
// const projectionCompiled = (projection as ProjectionBuilder<T>).compile();
this._whenBuilder.builder += " ".concat(type, " ").concat(projectionCompiled.projection);
this._whenBuilder.params = this._whenBuilder.params.concat(projectionCompiled.params);
}
else {
this._whenBuilder.builder += " ".concat(type, " ").concat(utils_1.Utils.getValueType(projection));
}
return this;
};
return ProjectionCaseWhen;
}());
exports.ProjectionCaseWhen = ProjectionCaseWhen;