hedera-web/js/sql/operation.js

91 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-09-26 09:28:47 +00:00
var Expr = require ('./expr');
/**
* The equivalent of a SQL operation between exprs.
*
* @param {Array#Sql.Expr} expr Array with the exprs
* @param {Sql..Operation.Type} type The type of the operation
2016-12-20 09:32:17 +00:00
*/
2016-09-26 09:28:47 +00:00
var Operation = new Class ();
module.exports = Operation;
var Type =
{
EQUAL : 0
,LIKE : 1
,AND : 2
,OR : 3
,REGEXP : 4
};
var Operators =
[
'='
,'LIKE'
,'AND'
,'OR'
,'REGEXP'
];
Operation.extend
({
2016-09-26 09:28:47 +00:00
Type: Type
,Operators: Operators
});
2016-09-26 09:28:47 +00:00
Operation.implement
({
2016-09-26 09:28:47 +00:00
Extends: Expr
,Tag: 'sql-operation'
,Properties:
{
type:
{
2016-09-26 09:28:47 +00:00
enumType: Type
,value: -1
}
}
,initialize: function (props)
{
this.parent (props);
this.link ({exprs: new Sql.List ()}, {'changed': this.onListChange});
}
2015-11-09 08:14:33 +00:00
,appendChild: function (child)
{
this.exprs.add (child);
}
,onListChange: function ()
{
this.signalEmit ('changed');
}
,isReady: function ()
{
return this.exprs.isReady ();
}
,render: function (batch)
{
var sql = '(';
2016-09-26 09:28:47 +00:00
var operator = ' '+ Operators[this.type] +' ';
var e = this.exprs.getArray ();
for (var i = 0; i < e.length; i++)
{
if (i > 0)
sql += operator;
sql += e[i].render (batch);
}
sql += ')';
return sql;
}
});
2016-09-26 09:28:47 +00:00