sedk-mysql
Version:
Simple SQL builder and validator for MySQL
122 lines • 5.39 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BooleanColumn = void 0;
const binder_1 = require("../binder");
const Column_1 = require("./Column");
const models_1 = require("../models");
const operators_1 = require("../operators");
const singletoneConstants_1 = require("../singletoneConstants");
const UpdateSetItemInfo_1 = require("../UpdateSetItemInfo");
class BooleanColumn extends Column_1.Column {
getColumns() {
return [this];
}
eq(value) {
if (value === null || value instanceof singletoneConstants_1.Default) {
return new UpdateSetItemInfo_1.UpdateSetItemInfo(this, value);
}
return new models_1.UpdateCondition(this, models_1.Expression.getSimpleExp(value));
}
eq$(value) {
const binder = new binder_1.Binder(value);
if (value === null) {
return new UpdateSetItemInfo_1.UpdateSetItemInfo(this, models_1.Expression.getSimpleExp(binder));
}
return new models_1.UpdateCondition(this, models_1.Expression.getSimpleExp(binder));
}
ne(value) {
return new models_1.Condition({
leftExpression: models_1.Expression.getSimpleExp(this),
operator: operators_1.ComparisonOperator.NotEqual,
rightExpression: models_1.Expression.getSimpleExp(value),
});
}
ne$(value) {
const binder = new binder_1.Binder(value);
return new models_1.Condition({
leftExpression: models_1.Expression.getSimpleExp(this),
operator: operators_1.ComparisonOperator.NotEqual,
rightExpression: models_1.Expression.getSimpleExp(binder),
});
}
// END implement Condition
constructor(data) {
super(data);
// START implement Condition
this.leftOperand = new models_1.ConditionOperand(models_1.Expression.getSimpleExp(this));
this.type = models_1.ExpressionType.BOOLEAN;
}
isEq(value) {
const qualifier = value === null ? operators_1.NullOperator.Is : operators_1.ComparisonOperator.Equal;
return new models_1.Condition({
leftExpression: models_1.Expression.getSimpleExp(this),
operator: qualifier,
rightExpression: models_1.Expression.getSimpleExp(value),
});
}
isEq$(value) {
const qualifier = value === null ? operators_1.NullOperator.Is : operators_1.ComparisonOperator.Equal;
const binder = new binder_1.Binder(value);
return new models_1.Condition({
leftExpression: models_1.Expression.getSimpleExp(this),
operator: qualifier,
rightExpression: models_1.Expression.getSimpleExp(binder),
});
}
isNe(value) {
const qualifier = value === null ? operators_1.NullOperator.IsNot : operators_1.ComparisonOperator.NotEqual;
return new models_1.Condition({
leftExpression: models_1.Expression.getSimpleExp(this),
operator: qualifier,
rightExpression: models_1.Expression.getSimpleExp(value),
});
}
isNe$(value) {
const qualifier = value === null ? operators_1.NullOperator.IsNot : operators_1.ComparisonOperator.NotEqual;
const binder = new binder_1.Binder(value);
return new models_1.Condition({
leftExpression: models_1.Expression.getSimpleExp(this),
operator: qualifier,
rightExpression: models_1.Expression.getSimpleExp(binder),
});
}
get NOT() {
return new models_1.Condition({ leftExpression: models_1.Expression.getSimpleExp(this, true) });
}
in(...values) {
Column_1.Column.throwIfArrayIsEmpty(values, operators_1.ComparisonOperator.In);
return new models_1.Condition({
leftExpression: models_1.Expression.getSimpleExp(this),
operator: operators_1.ComparisonOperator.In,
rightExpression: models_1.Expression.getSimpleExp(values),
});
}
in$(...values) {
Column_1.Column.throwIfArrayIsEmpty(values, operators_1.ComparisonOperator.In);
const binderArray = new binder_1.BinderArray(values.map(it => new binder_1.Binder(it)));
return new models_1.Condition({
leftExpression: models_1.Expression.getSimpleExp(this),
operator: operators_1.ComparisonOperator.In,
rightExpression: models_1.Expression.getSimpleExp(binderArray),
});
}
notIn(...values) {
Column_1.Column.throwIfArrayIsEmpty(values, operators_1.ComparisonOperator.NotIn);
return new models_1.Condition({
leftExpression: models_1.Expression.getSimpleExp(this),
operator: operators_1.ComparisonOperator.NotIn,
rightExpression: models_1.Expression.getSimpleExp(values),
});
}
notIn$(...values) {
Column_1.Column.throwIfArrayIsEmpty(values, operators_1.ComparisonOperator.NotIn);
const binderArray = new binder_1.BinderArray(values.map(it => new binder_1.Binder(it)));
return new models_1.Condition({
leftExpression: models_1.Expression.getSimpleExp(this),
operator: operators_1.ComparisonOperator.NotIn,
rightExpression: models_1.Expression.getSimpleExp(binderArray),
});
}
}
exports.BooleanColumn = BooleanColumn;
//# sourceMappingURL=BooleanColumn.js.map