2016-09-26 09:28:47 +00:00
|
|
|
|
2022-06-06 08:53:59 +00:00
|
|
|
var Expr = require('./expr');
|
|
|
|
var ListHolder = require('./list-holder');
|
2016-09-26 09:28:47 +00:00
|
|
|
|
2015-01-23 13:09:30 +00:00
|
|
|
/**
|
|
|
|
* The equivalent of a SQL operation between exprs.
|
|
|
|
*
|
2022-05-30 01:30:33 +00:00
|
|
|
* @param {Array#Expr} exprs Array with the exprs
|
|
|
|
* @param {Type} type The type of the operation
|
2022-05-26 06:08:31 +00:00
|
|
|
*/
|
2022-06-06 08:53:59 +00:00
|
|
|
var Klass = new Class();
|
2022-05-30 01:30:33 +00:00
|
|
|
module.exports = Klass;
|
2016-09-26 09:28:47 +00:00
|
|
|
|
2022-06-06 08:53:59 +00:00
|
|
|
var Type = {
|
2016-09-26 09:28:47 +00:00
|
|
|
EQUAL : 0
|
|
|
|
,LIKE : 1
|
|
|
|
,AND : 2
|
|
|
|
,OR : 3
|
|
|
|
,REGEXP : 4
|
2022-05-30 01:30:33 +00:00
|
|
|
,LOWER : 5
|
|
|
|
,UPPER : 6
|
|
|
|
,LE : 7
|
|
|
|
,UE : 8
|
|
|
|
,PLUS : 9
|
|
|
|
,MINUS : 10
|
|
|
|
,MULT : 11
|
|
|
|
,DIV : 12
|
|
|
|
,NE : 13
|
|
|
|
,MOD : 14
|
2016-09-26 09:28:47 +00:00
|
|
|
};
|
|
|
|
|
2022-06-06 08:53:59 +00:00
|
|
|
var Operators = [
|
2016-09-26 09:28:47 +00:00
|
|
|
'='
|
|
|
|
,'LIKE'
|
|
|
|
,'AND'
|
|
|
|
,'OR'
|
|
|
|
,'REGEXP'
|
2022-05-30 01:30:33 +00:00
|
|
|
,'<'
|
|
|
|
,'>'
|
|
|
|
,'<='
|
|
|
|
,'>='
|
|
|
|
,'+'
|
|
|
|
,'-'
|
|
|
|
,'*'
|
|
|
|
,'/'
|
|
|
|
,'<>'
|
|
|
|
,'MOD'
|
2016-09-26 09:28:47 +00:00
|
|
|
];
|
|
|
|
|
2022-06-06 08:53:59 +00:00
|
|
|
Klass.extend({
|
2016-09-26 09:28:47 +00:00
|
|
|
Type: Type
|
|
|
|
,Operators: Operators
|
2015-01-23 13:09:30 +00:00
|
|
|
});
|
|
|
|
|
2022-06-06 08:53:59 +00:00
|
|
|
Klass.implement({
|
2016-09-26 09:28:47 +00:00
|
|
|
Extends: Expr
|
2022-05-30 01:30:33 +00:00
|
|
|
,Implements: ListHolder
|
2015-01-23 13:09:30 +00:00
|
|
|
,Tag: 'sql-operation'
|
2022-06-06 08:53:59 +00:00
|
|
|
,Properties: {
|
|
|
|
type: {
|
2016-09-26 09:28:47 +00:00
|
|
|
enumType: Type
|
2015-01-23 13:09:30 +00:00
|
|
|
,value: -1
|
2022-05-30 01:30:33 +00:00
|
|
|
},
|
2022-06-06 08:53:59 +00:00
|
|
|
target: {
|
2022-05-30 01:30:33 +00:00
|
|
|
type: String
|
|
|
|
,value: null
|
|
|
|
},
|
2022-06-06 08:53:59 +00:00
|
|
|
exprs: {
|
2022-05-30 01:30:33 +00:00
|
|
|
type: Array
|
2022-06-06 08:53:59 +00:00
|
|
|
,set: function(x) {
|
2022-05-30 01:30:33 +00:00
|
|
|
this.list = x;
|
|
|
|
}
|
2022-06-06 08:53:59 +00:00
|
|
|
,get: function() {
|
2022-05-30 01:30:33 +00:00
|
|
|
return this.list;
|
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-06 08:53:59 +00:00
|
|
|
,render: function(params) {
|
2016-09-26 09:28:47 +00:00
|
|
|
var operator = ' '+ Operators[this.type] +' ';
|
2022-05-30 01:30:33 +00:00
|
|
|
return '('
|
2022-06-06 08:53:59 +00:00
|
|
|
+ this.renderListWs(this.list, params, operator)
|
2022-05-30 01:30:33 +00:00
|
|
|
+ ')';
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
});
|