hedera-web/js/sql/filter.js

50 lines
1011 B
JavaScript
Raw Normal View History

2016-09-26 09:28:47 +00:00
2022-06-06 08:53:59 +00:00
var Operation = require('./operation');
var Value = require('./value');
2016-09-26 09:28:47 +00:00
/**
2022-05-30 01:30:33 +00:00
* The equivalent of a SQL filter expression. It allows to automatically build
* SQL filters based on lot parameters.
2022-05-26 06:08:31 +00:00
*/
2022-06-06 08:53:59 +00:00
module.exports = new Class({
2016-09-26 09:28:47 +00:00
Extends: Operation
,Tag: 'sql-filter'
2022-05-30 01:30:33 +00:00
/**
* Checks if any of filters childs are ready.
*/
2022-11-16 01:46:44 +00:00
,isReady(params) {
2022-05-30 01:30:33 +00:00
var exprs = this.exprs;
for (var i = exprs.length; i--;)
2022-06-06 08:53:59 +00:00
if (exprs[i].isReady(params))
return true;
2022-05-30 01:30:33 +00:00
return false;
}
2022-05-30 01:30:33 +00:00
/**
* Renders the filter as an SQL expression. If any of its childs isn't
* ready is ommitted from the expression. If all of its childs aren't ready
* renders the TRUE expression.
*/
2022-11-16 01:46:44 +00:00
,render(params) {
2022-05-30 01:30:33 +00:00
var newOp;
var newExprs = [];
2022-06-06 08:53:59 +00:00
this.exprs.forEach(function(expr) {
if (expr.isReady(params))
newExprs.push(expr);
2022-05-30 01:30:33 +00:00
})
2022-05-30 01:30:33 +00:00
if (newExprs.length > 0)
2022-06-06 08:53:59 +00:00
newOp = new Operation({
2022-05-30 01:30:33 +00:00
type: this.type,
exprs: newExprs
});
else
2022-06-06 08:53:59 +00:00
newOp = new Value({value: true});
2022-06-06 08:53:59 +00:00
return newOp.render(params);
}
});