mirror of https://gitee.com/bigwinds/arangodb
Updated AQB to 1.10.0.
This commit is contained in:
parent
d3a041c95f
commit
fe281e2699
|
@ -223,16 +223,34 @@ Creates a range expression from the given values.
|
|||
|
||||
`qb.range(value1, value2)` => `value1..value2`
|
||||
|
||||
OR:
|
||||
|
||||
`aqlValue.range(value2)` => `value1..value2`
|
||||
|
||||
If the values are not already AQL values, they will be converted automatically.
|
||||
|
||||
*Alias:* `qb.to(value1, value2)`
|
||||
|
||||
**Examples**
|
||||
|
||||
`qb(2).to(5)` => `2..5`
|
||||
|
||||
### Property Access
|
||||
|
||||
Creates a property access expression from the given values.
|
||||
|
||||
`qb.get(obj, key)` => `obj[key]`
|
||||
|
||||
OR:
|
||||
|
||||
`aqlObj.get(key)` => `obj[key]`
|
||||
|
||||
If the values are not already AQL values, they will be converted automatically.
|
||||
|
||||
**Examples**
|
||||
|
||||
`qb.ref('x').get('y') => `x[y]`
|
||||
|
||||
### Raw Expression
|
||||
|
||||
Wraps a given value in a raw AQL expression.
|
||||
|
@ -251,13 +269,17 @@ Creates an "and" operation from the given values.
|
|||
|
||||
`qb.and(a, b)` => `(a && b)`
|
||||
|
||||
OR:
|
||||
|
||||
`aqlValue.and(b)` => `(a && b)`
|
||||
|
||||
If the values are not already AQL values, they will be converted automatically.
|
||||
|
||||
This function can take any number of arguments.
|
||||
|
||||
**Examples**
|
||||
|
||||
`qb.and(a, b, c, d, e, f)` => `(a && b && c && d && e && f)`
|
||||
`qb.ref('x').and('y')` => `(x && y)`
|
||||
|
||||
### Boolean Or
|
||||
|
||||
|
@ -265,13 +287,17 @@ Creates an "or" operation from the given values.
|
|||
|
||||
`qb.or(a, b)` => `(a || b)`
|
||||
|
||||
OR:
|
||||
|
||||
`aqlValue.or(b)` => `(a || b)`
|
||||
|
||||
If the values are not already AQL values, they will be converted automatically.
|
||||
|
||||
This function can take any number of arguments.
|
||||
|
||||
**Examples**
|
||||
|
||||
`qb.or(a, b, c, d, e, f)` => `(a || b || c || d || e || f)`
|
||||
`qb.ref('x').or('y')` => `(x || y)`
|
||||
|
||||
### Addition
|
||||
|
||||
|
@ -279,6 +305,10 @@ Creates an addition operation from the given values.
|
|||
|
||||
`qb.add(a, b)` => `(a + b)`
|
||||
|
||||
OR:
|
||||
|
||||
`aqlValue.add(b)` => `(a + b)`
|
||||
|
||||
If the values are not already AQL values, they will be converted automatically.
|
||||
|
||||
This function can take any number of arguments.
|
||||
|
@ -287,7 +317,7 @@ This function can take any number of arguments.
|
|||
|
||||
**Examples**
|
||||
|
||||
`qb.add(a, b, c, d, e, f)` => `(a + b + c + d + e + f)`
|
||||
`qb.ref('x').plus('y')` => `(x + y)`
|
||||
|
||||
### Subtraction
|
||||
|
||||
|
@ -295,6 +325,10 @@ Creates a subtraction operation from the given values.
|
|||
|
||||
`qb.sub(a, b)` => `(a - b)`
|
||||
|
||||
OR:
|
||||
|
||||
`aqlValue.sub(b)` => `(a - b)`
|
||||
|
||||
If the values are not already AQL values, they will be converted automatically.
|
||||
|
||||
This function can take any number of arguments.
|
||||
|
@ -303,7 +337,7 @@ This function can take any number of arguments.
|
|||
|
||||
**Examples**
|
||||
|
||||
`qb.sub(a, b, c, d, e, f)` => `(a - b - c - d - e - f)`
|
||||
`qb.ref('x').minus('y')` => `(x - y)`
|
||||
|
||||
### Multiplication
|
||||
|
||||
|
@ -311,6 +345,10 @@ Creates a multiplication operation from the given values.
|
|||
|
||||
`qb.mul(a, b)` => `(a * b)`
|
||||
|
||||
OR:
|
||||
|
||||
`aqlValue.mul(b)` => `(a * b)`
|
||||
|
||||
If the values are not already AQL values, they will be converted automatically.
|
||||
|
||||
This function can take any number of arguments.
|
||||
|
@ -319,7 +357,7 @@ This function can take any number of arguments.
|
|||
|
||||
**Examples**
|
||||
|
||||
`qb.mul(a, b, c, d, e, f)` => `(a * b * c * d * e * f)`
|
||||
`qb.ref('x').times('y')` => `(x * y)`
|
||||
|
||||
### Division
|
||||
|
||||
|
@ -327,13 +365,17 @@ Creates a division operation from the given values.
|
|||
|
||||
`qb.div(a, b)` => `(a / b)`
|
||||
|
||||
OR:
|
||||
|
||||
`aqlValue.div(b)` => `(a / b)`
|
||||
|
||||
If the values are not already AQL values, they will be converted automatically.
|
||||
|
||||
This function can take any number of arguments.
|
||||
|
||||
**Examples**
|
||||
|
||||
`qb.div(a, b, c, d, e, f)` => `(a / b / c / d / e / f)`
|
||||
`qb.ref('x').div('y')` => `(x / y)`
|
||||
|
||||
### Modulus
|
||||
|
||||
|
@ -341,13 +383,17 @@ Creates a modulus operation from the given values.
|
|||
|
||||
`qb.mod(a, b)` => `(a % b)`
|
||||
|
||||
OR:
|
||||
|
||||
`aqlValue.mod(b)` => `(a % b)`
|
||||
|
||||
If the values are not already AQL values, they will be converted automatically.
|
||||
|
||||
This function can take any number of arguments.
|
||||
|
||||
**Examples**
|
||||
|
||||
`qb.mod(a, b, c, d, e, f)` => `(a % b % c % d % e % f)`
|
||||
`qb.ref('x').mod('y')` => `(x % y)`
|
||||
|
||||
### Equality
|
||||
|
||||
|
@ -355,83 +401,167 @@ Creates an equality comparison from the given values.
|
|||
|
||||
`qb.eq(a, b)` => `(a == b)`
|
||||
|
||||
OR:
|
||||
|
||||
`qbValue.eq(b)` => `(a == b)`
|
||||
|
||||
If the values are not already AQL values, they will be converted automatically.
|
||||
|
||||
**Examples**
|
||||
|
||||
`qb.ref('x').eq('y')` => `(x == y)`
|
||||
|
||||
### Inequality
|
||||
|
||||
Creates an inequality comparison from the given values.
|
||||
|
||||
`qb.neq(a, b)` => `(a != b)`
|
||||
|
||||
OR:
|
||||
|
||||
`qbValue.neq(b)` => `(a != b)`
|
||||
|
||||
If the values are not already AQL values, they will be converted automatically.
|
||||
|
||||
**Examples**
|
||||
|
||||
`qb.ref('x').neq('y')` => `(x != y)`
|
||||
|
||||
### Greater Than
|
||||
|
||||
Creates a greater-than comparison from the given values.
|
||||
|
||||
`qb.gt(a, b)` => `(a > b)`
|
||||
|
||||
OR
|
||||
|
||||
`qbValue.gt(b)` => `(a > b)`
|
||||
|
||||
If the values are not already AQL values, they will be converted automatically.
|
||||
|
||||
**Examples**
|
||||
|
||||
`qb.ref('x').gt('y')` => `(x > y)`
|
||||
|
||||
### Greater Than Or Equal To
|
||||
|
||||
Creates a greater-than-or-equal-to comparison from the given values.
|
||||
|
||||
`qb.gte(a, b)` => `(a >= b)`
|
||||
|
||||
OR
|
||||
|
||||
`qbValue.gte(b)` => `(a >= b)`
|
||||
|
||||
If the values are not already AQL values, they will be converted automatically.
|
||||
|
||||
**Examples**
|
||||
|
||||
`qb.ref('x').gte('y')` => `(x >= y)`
|
||||
|
||||
### Less Than
|
||||
|
||||
Creates a less-than comparison from the given values.
|
||||
|
||||
`qb.lt(a, b)` => `(a < b)`
|
||||
|
||||
OR
|
||||
|
||||
`qbValue.lt(b)` => `(a < b)`
|
||||
|
||||
If the values are not already AQL values, they will be converted automatically.
|
||||
|
||||
**Examples**
|
||||
|
||||
`qb.ref('x').lt('y')` => `(x < y)`
|
||||
|
||||
### Less Than Or Equal To
|
||||
|
||||
Creates a less-than-or-equal-to comparison from the given values.
|
||||
|
||||
`qb.lte(a, b)` => `(a <= b)`
|
||||
|
||||
OR
|
||||
|
||||
`qbValue.lte(b)` => `(a <= b)`
|
||||
|
||||
If the values are not already AQL values, they will be converted automatically.
|
||||
|
||||
**Examples**
|
||||
|
||||
`qb.ref('x').lte('y')` => `(x <= y)`
|
||||
|
||||
### Contains
|
||||
|
||||
Creates an "in" comparison from the given values.
|
||||
|
||||
`qb.in(a, b)` => `(a in b)`
|
||||
|
||||
OR:
|
||||
|
||||
`qbValue.in(b)` => `(a in b)`
|
||||
|
||||
If the values are not already AQL values, they will be converted automatically.
|
||||
|
||||
*Aliases:* `qb.in_(a, b)`
|
||||
|
||||
**Examples**
|
||||
|
||||
`qb.ref('x').in('y')` => `(x in y)`
|
||||
|
||||
### Negation
|
||||
|
||||
Creates a negation from the given value.
|
||||
|
||||
`qb.not(a)` => `!(a)`
|
||||
|
||||
OR:
|
||||
|
||||
`qbValue.not()` => `!(a)`
|
||||
|
||||
If the value is not already an AQL value, it will be converted automatically.
|
||||
|
||||
**Examples**
|
||||
|
||||
`qb.not('x')` => `!(x)`
|
||||
|
||||
### Negative Value
|
||||
|
||||
Creates a negative value expression from the given value.
|
||||
|
||||
`qb.neg(a)` => `-(a)`
|
||||
|
||||
OR:
|
||||
|
||||
`qbValue.neg()` => `-(a)`
|
||||
|
||||
If the value is not already an AQL value, it will be converted automatically.
|
||||
|
||||
**Examples**
|
||||
|
||||
`qb.neg('x')` => `-(x)`
|
||||
|
||||
### Ternary (if / else)
|
||||
|
||||
Creates a ternary expression from the given values.
|
||||
|
||||
`qb.if(condition, then, otherwise)` => `(condition ? then : otherwise)`
|
||||
`qb.if(condition, thenDo, elseDo)` => `(condition ? thenDo : elseDo)`
|
||||
|
||||
OR:
|
||||
|
||||
`qbValue.then(thenDo).else(elseDo)` => `(condition ? thenDo : elseDo)`
|
||||
|
||||
If the values are not already AQL values, they will be converted automatically.
|
||||
|
||||
*Aliases:* `qb.if_(condition, then, otherwise)`
|
||||
*Aliases:*
|
||||
|
||||
* `qb.if_(condition, thenDo, elseDo)`
|
||||
* `qbValue.then(thenDo).else_(elseDo)
|
||||
* `qbValue.then(thenDo).otherwise(elseDo)`
|
||||
|
||||
**Examples**
|
||||
|
||||
`qb.ref('x').then('y').else('z')` => `(x ? y : z)`
|
||||
|
||||
### Function Call
|
||||
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
/*jshint browserify: true */
|
||||
/*globals console: false */
|
||||
'use strict';
|
||||
var AqlError = require('./errors').AqlError,
|
||||
assumptions = require('./assumptions'),
|
||||
types = require('./types'),
|
||||
toArray,
|
||||
warn;
|
||||
var AqlError = require('./errors').AqlError;
|
||||
var assumptions = require('./assumptions');
|
||||
var types = require('./types');
|
||||
|
||||
toArray = Function.prototype.call.bind(Array.prototype.slice);
|
||||
|
||||
warn = (function () {
|
||||
var warn = (function () {
|
||||
if (typeof console !== 'undefined') {
|
||||
return function () {return console.warn.apply(console, arguments);};
|
||||
}
|
||||
|
@ -51,39 +47,47 @@ Object.keys(types._PartialStatement.prototype).forEach(function (key) {
|
|||
QB[key] = types._PartialStatement.prototype[key].bind(null);
|
||||
});
|
||||
|
||||
QB.bool = function (value) {return new types.BooleanLiteral(value);};
|
||||
QB.num = function (value) {return new types.NumberLiteral(value);};
|
||||
QB.int_ = QB.int = function (value) {return new types.IntegerLiteral(value);};
|
||||
QB.str = function (value) {return new types.StringLiteral(value);};
|
||||
QB.list = function (arr) {return new types.ListLiteral(arr);};
|
||||
QB.obj = function (obj) {return new types.ObjectLiteral(obj);};
|
||||
QB.range = function (start, end) {return new types.RangeExpression(start, end);};
|
||||
QB.get = function (obj, key) {return new types.PropertyAccess(obj, key);};
|
||||
Object.keys(types._Expression.prototype).forEach(function (key) {
|
||||
if (key === 'constructor' || key === 'then') return;
|
||||
QB[key] = function () {
|
||||
return types._Expression.prototype[key].apply(
|
||||
types.autoCastToken(arguments[0]),
|
||||
Array.prototype.slice.call(arguments, 1)
|
||||
);
|
||||
};
|
||||
});
|
||||
|
||||
QB.if_ = QB.if = function (cond, then, otherwise) {
|
||||
return types.autoCastToken(cond).then(then).else(otherwise);
|
||||
};
|
||||
|
||||
QB.bool = function (value) {
|
||||
return new types.BooleanLiteral(value);
|
||||
};
|
||||
QB.num = function (value) {
|
||||
return new types.NumberLiteral(value);
|
||||
};
|
||||
QB.int_ = QB.int = function (value) {
|
||||
return new types.IntegerLiteral(value);
|
||||
};
|
||||
QB.str = function (value) {
|
||||
return new types.StringLiteral(value);
|
||||
};
|
||||
QB.list = function (arr) {
|
||||
return new types.ListLiteral(arr);
|
||||
};
|
||||
QB.obj = function (obj) {
|
||||
return new types.ObjectLiteral(obj);
|
||||
};
|
||||
QB.ref = function (value) {
|
||||
if (types.Identifier.re.exec(value)) {
|
||||
return new types.Identifier(value);
|
||||
}
|
||||
return new types.SimpleReference(value);
|
||||
};
|
||||
QB.expr = function (value) {return new types.RawExpression(value);};
|
||||
|
||||
QB.and = function (/* x, y... */) {return new types.NAryOperation('&&', toArray(arguments));};
|
||||
QB.or = function (/* x, y... */) {return new types.NAryOperation('||', toArray(arguments));};
|
||||
QB.plus = QB.add = function (/* x, y... */) {return new types.NAryOperation('+', toArray(arguments));};
|
||||
QB.minus = QB.sub = function (/* x, y... */) {return new types.NAryOperation('-', toArray(arguments));};
|
||||
QB.times = QB.mul = function (/* x, y... */) {return new types.NAryOperation('*', toArray(arguments));};
|
||||
QB.div = function (/* x, y... */) {return new types.NAryOperation('/', toArray(arguments));};
|
||||
QB.mod = function (/* x, y... */) {return new types.NAryOperation('%', toArray(arguments));};
|
||||
QB.eq = function (x, y) {return new types.BinaryOperation('==', x, y);};
|
||||
QB.gt = function (x, y) {return new types.BinaryOperation('>', x, y);};
|
||||
QB.gte = function (x, y) {return new types.BinaryOperation('>=', x, y);};
|
||||
QB.lt = function (x, y) {return new types.BinaryOperation('<', x, y);};
|
||||
QB.lte = function (x, y) {return new types.BinaryOperation('<=', x, y);};
|
||||
QB.neq = function (x, y) {return new types.BinaryOperation('!=', x, y);};
|
||||
QB.not = function (x) {return new types.UnaryOperation('!', x);};
|
||||
QB.neg = function (x) {return new types.UnaryOperation('-', x);};
|
||||
QB.in_ = QB.in = function (x, y) {return new types.BinaryOperation('in', x, y);};
|
||||
QB.if_ = QB.if = function (x, y, z) {return new types.TernaryOperation('?', ':', x, y, z);};
|
||||
QB.expr = function (value) {
|
||||
return new types.RawExpression(value);
|
||||
};
|
||||
|
||||
QB.fn = function (functionName, arity) {
|
||||
if (typeof arity === 'number') {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -3,6 +3,12 @@
|
|||
var AqlError = require('./errors').AqlError;
|
||||
var keywords = require('./assumptions').keywords;
|
||||
|
||||
function toArray(self, args) {
|
||||
var arr = Array.prototype.slice.call(args);
|
||||
arr.unshift(self);
|
||||
return arr;
|
||||
}
|
||||
|
||||
function isQuotedString(str) {
|
||||
return (
|
||||
str.length >= 2 &&
|
||||
|
@ -76,7 +82,7 @@ function autoCastToken(token) {
|
|||
return token;
|
||||
}
|
||||
var type = typeof token;
|
||||
if (Object.keys(autoCastToken).indexOf(type) === -1) {
|
||||
if (!autoCastToken.hasOwnProperty(type)) {
|
||||
throw new AqlError('Invalid AQL value: (' + type + ') ' + token);
|
||||
}
|
||||
return autoCastToken[type](token);
|
||||
|
@ -87,6 +93,69 @@ autoCastToken.string = castString;
|
|||
autoCastToken.object = castObject;
|
||||
|
||||
function Expression() {}
|
||||
Expression.prototype.range = Expression.prototype.to = function (max) {
|
||||
return new RangeExpression(this, max);
|
||||
};
|
||||
Expression.prototype.get = function (key) {
|
||||
return new PropertyAccess(this, key);
|
||||
};
|
||||
Expression.prototype.and = function (/* x, y... */) {
|
||||
return new NAryOperation('&&', toArray(this, arguments));
|
||||
};
|
||||
Expression.prototype.or = function (/* x, y... */) {
|
||||
return new NAryOperation('||', toArray(this, arguments));
|
||||
};
|
||||
Expression.prototype.add = Expression.prototype.plus = function (/* x, y... */) {
|
||||
return new NAryOperation('+', toArray(this, arguments));
|
||||
};
|
||||
Expression.prototype.sub = Expression.prototype.minus = function (/* x, y... */) {
|
||||
return new NAryOperation('-', toArray(this, arguments));
|
||||
};
|
||||
Expression.prototype.mul = Expression.prototype.times = function (/* x, y... */) {
|
||||
return new NAryOperation('*', toArray(this, arguments));
|
||||
};
|
||||
Expression.prototype.div = function (/* x, y... */) {
|
||||
return new NAryOperation('/', toArray(this, arguments));
|
||||
};
|
||||
Expression.prototype.mod = function (/* x, y... */) {
|
||||
return new NAryOperation('%', toArray(this, arguments));
|
||||
};
|
||||
Expression.prototype.eq = function (x) {
|
||||
return new BinaryOperation('==', this, x);
|
||||
};
|
||||
Expression.prototype.gt = function (x) {
|
||||
return new BinaryOperation('>', this, x);
|
||||
};
|
||||
Expression.prototype.gte = function (x) {
|
||||
return new BinaryOperation('>=', this, x);
|
||||
};
|
||||
Expression.prototype.lt = function (x) {
|
||||
return new BinaryOperation('<', this, x);
|
||||
};
|
||||
Expression.prototype.lte = function (x) {
|
||||
return new BinaryOperation('<=', this, x);
|
||||
};
|
||||
Expression.prototype.neq = function (x) {
|
||||
return new BinaryOperation('!=', this, x);
|
||||
};
|
||||
Expression.prototype.not = function () {
|
||||
return new UnaryOperation('!', this);
|
||||
};
|
||||
Expression.prototype.neg = function () {
|
||||
return new UnaryOperation('-', this);
|
||||
};
|
||||
Expression.prototype.in_ = Expression.prototype.in = function (x) {
|
||||
return new BinaryOperation('in', this, x);
|
||||
};
|
||||
Expression.prototype.then = function (x) {
|
||||
var self = this;
|
||||
var elseFn = function (y) {
|
||||
return new TernaryOperation('?', ':', self, x, y);
|
||||
};
|
||||
return {else: elseFn, else_: elseFn, otherwise: elseFn};
|
||||
};
|
||||
|
||||
|
||||
function Operation() {}
|
||||
Operation.prototype = new Expression();
|
||||
Operation.prototype.constructor = Operation;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"aqb": "1.9.0",
|
||||
"aqb": "1.10.0",
|
||||
"chai": "2.2.0",
|
||||
"coffee-script": "1.9.1",
|
||||
"error-stack-parser": "1.2.0",
|
||||
|
|
Loading…
Reference in New Issue