UNPKG

sphinxql

Version:

SphinxQL query builder for Node.JS. Supports Sphinx search(2.x and 3.x) and Manticore search

72 lines 3.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var MatchStatement_1 = require("./statement_expressions/MatchStatement"); var WhereStatement_1 = require("./statement_expressions/WhereStatement"); var BaseStatement_1 = require("./BaseStatement"); var DeleteStatement = (function (_super) { tslib_1.__extends(DeleteStatement, _super); function DeleteStatement(connection, index) { var _this = _super.call(this, connection) || this; _this.matchStatement = new MatchStatement_1.default(); _this.whereConditions = []; _this.index = index; return _this; } DeleteStatement.prototype.where = function (columnExpr, operator, value) { if (value === undefined) { value = operator; operator = '='; } var condition = new WhereStatement_1.default(columnExpr, operator, value); this.whereConditions = tslib_1.__spreadArrays(this.whereConditions, [condition]); return this; }; DeleteStatement.prototype.whereIn = function (column, values) { var condition = new WhereStatement_1.default(column, 'IN', values); this.whereConditions = tslib_1.__spreadArrays(this.whereConditions, [condition]); return this; }; DeleteStatement.prototype.whereNotIn = function (column, values) { var condition = new WhereStatement_1.default(column, 'NOT IN', values); this.whereConditions = tslib_1.__spreadArrays(this.whereConditions, [condition]); return this; }; DeleteStatement.prototype.between = function (column, value1, value2) { var condtion = new WhereStatement_1.default(column, 'BETWEEN', [value1, value2]); this.whereConditions = tslib_1.__spreadArrays(this.whereConditions, [condtion]); return this; }; DeleteStatement.prototype.match = function (fields, value, escapeValue) { if (escapeValue === void 0) { escapeValue = true; } this.matchStatement.match(fields.length ? fields : undefined, value, escapeValue); return this; }; DeleteStatement.prototype.orMatch = function (fields, value, escapeValue) { if (escapeValue === void 0) { escapeValue = true; } this.matchStatement.orMatch(fields.length ? fields : undefined, value, escapeValue); return this; }; DeleteStatement.prototype.generate = function () { var statement = 'DELETE FROM '; statement += this.index; var hasMatchStatement = this.matchStatement.getParts().length > 0; var hasWhereStatements = this.whereConditions.length > 0; if (hasWhereStatements || hasMatchStatement) { statement += ' WHERE '; if (hasMatchStatement) { statement += "MATCH(" + this.matchStatement.build() + ")"; if (hasWhereStatements) { statement += ' AND '; } } var stringStatements = void 0; stringStatements = this.whereConditions.map(function (condition) { return condition.build(); }); statement += stringStatements.join(' AND '); } return statement; }; return DeleteStatement; }(BaseStatement_1.default)); exports.default = DeleteStatement; //# sourceMappingURL=DeleteStatement.js.map