UNPKG

4.23 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3/**
4 * Find Operator used in Find Conditions.
5 */
6var FindOperator = /** @class */ (function () {
7 // -------------------------------------------------------------------------
8 // Constructor
9 // -------------------------------------------------------------------------
10 function FindOperator(type, value, useParameter, multipleParameters) {
11 if (useParameter === void 0) { useParameter = true; }
12 if (multipleParameters === void 0) { multipleParameters = false; }
13 this._type = type;
14 this._value = value;
15 this._useParameter = useParameter;
16 this._multipleParameters = multipleParameters;
17 }
18 Object.defineProperty(FindOperator.prototype, "useParameter", {
19 // -------------------------------------------------------------------------
20 // Accessors
21 // -------------------------------------------------------------------------
22 /**
23 * Indicates if parameter is used or not for this operator.
24 * Extracts final value if value is another find operator.
25 */
26 get: function () {
27 if (this._value instanceof FindOperator)
28 return this._value.useParameter;
29 return this._useParameter;
30 },
31 enumerable: true,
32 configurable: true
33 });
34 Object.defineProperty(FindOperator.prototype, "multipleParameters", {
35 /**
36 * Indicates if multiple parameters must be used for this operator.
37 * Extracts final value if value is another find operator.
38 */
39 get: function () {
40 if (this._value instanceof FindOperator)
41 return this._value.multipleParameters;
42 return this._multipleParameters;
43 },
44 enumerable: true,
45 configurable: true
46 });
47 Object.defineProperty(FindOperator.prototype, "value", {
48 /**
49 * Gets the final value needs to be used as parameter value.
50 */
51 get: function () {
52 if (this._value instanceof FindOperator)
53 return this._value.value;
54 return this._value;
55 },
56 enumerable: true,
57 configurable: true
58 });
59 // -------------------------------------------------------------------------
60 // Public Methods
61 // -------------------------------------------------------------------------
62 /**
63 * Gets SQL needs to be inserted into final query.
64 */
65 FindOperator.prototype.toSql = function (connection, aliasPath, parameters) {
66 switch (this._type) {
67 case "not":
68 if (this._value instanceof FindOperator) {
69 return "NOT(" + this._value.toSql(connection, aliasPath, parameters) + ")";
70 }
71 else {
72 return aliasPath + " != " + parameters[0];
73 }
74 case "lessThan":
75 return aliasPath + " < " + parameters[0];
76 case "lessThanOrEqual":
77 return aliasPath + " <= " + parameters[0];
78 case "moreThan":
79 return aliasPath + " > " + parameters[0];
80 case "moreThanOrEqual":
81 return aliasPath + " >= " + parameters[0];
82 case "equal":
83 return aliasPath + " = " + parameters[0];
84 case "like":
85 return aliasPath + " LIKE " + parameters[0];
86 case "between":
87 return aliasPath + " BETWEEN " + parameters[0] + " AND " + parameters[1];
88 case "in":
89 return aliasPath + " IN (" + parameters.join(", ") + ")";
90 case "any":
91 return aliasPath + " = ANY(" + parameters[0] + ")";
92 case "isNull":
93 return aliasPath + " IS NULL";
94 case "raw":
95 if (this.value instanceof Function) {
96 return this.value(aliasPath);
97 }
98 else {
99 return aliasPath + " = " + this.value;
100 }
101 }
102 return "";
103 };
104 return FindOperator;
105}());
106exports.FindOperator = FindOperator;
107
108//# sourceMappingURL=FindOperator.js.map