2016-09-26 09:28:47 +00:00
|
|
|
|
2022-05-30 01:30:33 +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-05-30 01:30:33 +00:00
|
|
|
var Klass = new Class ();
|
|
|
|
module.exports = Klass;
|
2016-09-26 09:28:47 +00:00
|
|
|
|
2022-05-30 01:30:33 +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-05-30 01:30:33 +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-05-30 01:30:33 +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-05-30 01:30:33 +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-05-30 01:30:33 +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
|
|
|
},
|
|
|
|
target:
|
|
|
|
{
|
|
|
|
type: String
|
|
|
|
,value: null
|
|
|
|
},
|
|
|
|
exprs:
|
|
|
|
{
|
|
|
|
type: Array
|
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
this.list = x;
|
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this.list;
|
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-30 01:30:33 +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 '('
|
|
|
|
+ this.renderListWs (this.list, params, operator)
|
|
|
|
+ ')';
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
});
|