Represents a complex SQL expression, with a given operator and one or more attributes (which may also be ComplexExpressions, forming a tree).
This is an abstract class that is not that useful by itself. The subclasses @link patio.sql.BooleanExpression}, patio.sql.NumericExpression and patio.sql.StringExpression should be used instead of this class directly.
ExtendsProperty | Type | Default Value | Description |
BITWISE_OPERATORS | Object |
{bitWiseAnd:"&", bitWiseOr:"|", exclusiveOr:"^", leftShift:"<<", rightShift:">>"}
| Default bitwise operators. |
BOOLEAN_OPERATORS | Object |
{AND:"AND",OR:"OR"}
| Default boolean operators. |
INEQUALITY_OPERATORS | Object |
{GT:">",GTE:">=",LT:"<",LTE:"<="}
| Default inequality operators. |
IN_OPERATORS | Object |
{IN:"IN",NOTIN:'NOT IN'}
| Default IN operators. |
IS_OPERATORS | Object |
{IS:"IS", ISNOT:'IS NOT'}
| Default IS operators. |
MATHEMATICAL_OPERATORS | Object |
{PLUS:"+", MINUS:"-", DIVIDE:"/", MULTIPLY:"*"}
| Default mathematical operators. |
N_ARITY_OPERATORS | Object |
{
"||":"||",
AND:"AND",
OR:"OR",
PLUS:"+",
MINUS:"-",
DIVIDE:"/", MULTIPLY:"*"
}
| Default N(multi) arity operators. |
ONE_ARITY_OPERATORS | Object |
{
"NOT":"NOT",
"NOOP":"NOOP"
}
| Default ONE operators. |
OPERATOR_INVERSIONS | Object |
{
AND:"OR",
OR:"AND",
GT:"lte",
GTE:"lt",
LT:"gte",
LTE:"gt",
EQ:"neq",
NEQ:"eq",
LIKE:'NOT LIKE',
"NOT LIKE":"LIKE",
'!~*':'~*',
'~*':'!~*',
"~":'!~',
"IN":'NOTIN',
"NOTIN":"IN",
"IS":'IS NOT',
"ISNOT":"IS",
NOT:"NOOP",
NOOP:"NOT",
ILIKE:'NOT ILIKE',
NOTILIKE:"ILIKE"
}
| Hash of operator inversions |
TWO_ARITY_OPERATORS | Object |
{
EQ:'=',
NEQ:'!=', LIKE:"LIKE",
"NOT LIKE":'NOT LIKE',
ILIKE:"ILIKE",
"NOT ILIKE":'NOT ILIKE',
"~":"~",
'!~':"!~",
'~*':"~*",
'!~*':"!~*",
GT:">",
GTE:">=",
LT:"<",
LTE:"<=",
bitWiseAnd:"&",
bitWiseOr:"|",
exclusiveOr:"^",
leftShift:"<<",
rightShift:">>",
IS:"IS",
ISNOT:'IS NOT',
IN:"IN",
NOTIN:'NOT IN'
}
| Default two arity operators. |
patio.sql.ExpressionError
if the operator doesn't allow boolean input and a boolean argument is given.
patio.sql.ExpressionError
if the wrong number of arguments for a given operator is used.
- function (op){
- if (op) {
- var args = argsToArray(arguments, 1);
- //make a copy of the args
- var origArgs = args.slice(0);
- args.forEach(function (a, i) {
- if (Expression.isConditionSpecifier(a)) {
- args[i] = BooleanExpression.fromValuePairs(a);
- }
- });
- op = op.toUpperCase();
- if (N_ARITY_OPERATORS.hasOwnProperty(op)) {
- if (args.length < 1) {
- throw new ExpressionError("The " + op + " operator requires at least 1 argument");
- }
- var oldArgs = args.slice(0);
- args = [];
- oldArgs.forEach(function (a) {
- a instanceof ComplexExpression && a.op === op ? args = args.concat(a.args) : args.push(a);
- });
- } else if (TWO_ARITY_OPERATORS.hasOwnProperty(op)) {
- if (args.length !== 2) {
- throw new ExpressionError("The " + op + " operator requires precisely 2 arguments");
- }
- //With IN/NOT IN, even if the second argument is an array of two element arrays,
- //don't convert it into a boolean expression, since it's definitely being used
- //as a value list.
- if (IN_OPERATORS[op]) {
- args[1] = origArgs[1];
- }
- } else if (ONE_ARITY_OPERATORS.hasOwnProperty(op)) {
- if (args.length !== 1) {
- throw new ExpressionError("The " + op + " operator requires only one argument");
- }
- } else {
- throw new ExpressionError("Invalid operator " + op);
- }
- this.op = op;
- this.args = args;
- }
- }
Converts the ComplexExpression to a string.
Argumentsdataset used to created the SQL fragment, if the dataset is ommited then the default patio.Dataset implementation is used.
String the SQL version of the patio.sql.ComplexExpression.
- function (ds){
- !Dataset && (Dataset = require("./dataset"));
- ds = ds || new Dataset();
- return ds.complexExpressionSql(this.op, this.args);
- }