sphinxql
Version:
SphinxQL query builder for Node.JS. Supports Sphinx search(2.x and 3.x) and Manticore search
57 lines • 2.02 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var sqlstring_1 = require("sqlstring");
var Expression_1 = require("./Expression");
var FilterCondition = (function () {
function FilterCondition(columnExpr, operator, value) {
if (!columnExpr.length) {
throw Error("column name can't be empty");
}
this.columnExpr = columnExpr;
this.operator = operator;
this.value = value;
}
FilterCondition.prototype.build = function () {
var expression = this.columnExpr;
if (this.operator.includes('IN')) {
expression += " " + this.buildIn();
}
else if (this.operator === 'BETWEEN') {
expression += this.buildBetween();
}
else {
expression += this.buildCondition();
}
return expression;
};
FilterCondition.getExpressionCompare = function (value) {
if (value instanceof Expression_1.default) {
return value.getExpression();
}
if (typeof value === 'string') {
return escape(value);
}
if (typeof value === 'number') {
return value;
}
return value;
};
FilterCondition.prototype.buildIn = function () {
var expression = '';
expression += this.operator + " ";
var values = '?'.repeat(this.value.length)
.split('')
.join(', ');
expression += "(" + sqlstring_1.format(values, this.value) + ")";
return expression;
};
FilterCondition.prototype.buildBetween = function () {
return sqlstring_1.format(" " + this.operator + " ? AND ?", this.value);
};
FilterCondition.prototype.buildCondition = function () {
return sqlstring_1.format(" " + this.operator + " ?", this.value);
};
return FilterCondition;
}());
exports.default = FilterCondition;
//# sourceMappingURL=FilterCondition.js.map