Comparing version 1.5.2 to 1.6.0
{ | ||
"name": "aqb", | ||
"version": "1.5.2", | ||
"version": "1.6.0", | ||
"description": "ArangoDB AQL query builder.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -465,2 +465,6 @@ # ArangoDB Query Builder | ||
### COLLECT var1 = expr1, var2 = expr2, …, varn = exprn INTO varname COUNT | ||
`PartialStatement::collect(definitions).into(varname).count() : Statement` | ||
### SORT args… | ||
@@ -467,0 +471,0 @@ |
135
types.js
@@ -243,3 +243,3 @@ /*jshint browserify: true */ | ||
var value = String(this.value); | ||
if (keywords.indexOf(value.toLowerCase()) === -1) { | ||
if (keywords.indexOf(value.toLowerCase()) === -1 && value.indexOf('-') === -1) { | ||
return value; | ||
@@ -510,3 +510,3 @@ } | ||
CollectExpression.prototype.into = function (varname) { | ||
return new CollectIntoExpression(this.prev, this.dfns, varname); | ||
return new CollectIntoExpression(this, varname); | ||
}; | ||
@@ -519,6 +519,9 @@ CollectExpression.prototype.toAQL = function () { | ||
}; | ||
CollectExpression.prototype.keep = function () { | ||
var args = Array.prototype.slice.call(arguments); | ||
return new CollectKeepExpression(this, args); | ||
}; | ||
function CollectIntoExpression(prev, dfns, varname) { | ||
function CollectIntoExpression(prev, varname) { | ||
this.prev = prev; | ||
this.dfns = new Definitions(dfns); | ||
this.varname = new Identifier(varname); | ||
@@ -531,7 +534,43 @@ } | ||
(this.prev ? this.prev.toAQL() + ' ' : '') + | ||
'COLLECT ' + this.dfns.toAQL() + | ||
' INTO ' + this.varname.toAQL() | ||
'INTO ' + this.varname.toAQL() | ||
); | ||
}; | ||
CollectIntoExpression.prototype.count = function () { | ||
return new CollectCountExpression(this); | ||
}; | ||
CollectIntoExpression.prototype.keep = CollectExpression.prototype.keep; | ||
function CollectCountExpression(prev) { | ||
this.prev = prev; | ||
} | ||
CollectCountExpression.prototype = new PartialStatement(); | ||
CollectCountExpression.prototype.constructor = CollectCountExpression; | ||
CollectCountExpression.prototype.toAQL = function () { | ||
return ( | ||
(this.prev ? this.prev.toAQL() + ' ' : '') + | ||
'COUNT' | ||
); | ||
}; | ||
CollectCountExpression.prototype.keep = CollectExpression.prototype.keep; | ||
function CollectKeepExpression(prev, args) { | ||
if (!args || !Array.isArray(args)) { | ||
throw new AqlError('Expected sort list to be an array: ' + args); | ||
} | ||
if (!args.length) { | ||
throw new AqlError('Expected sort list not to be empty: ' + args); | ||
} | ||
this.prev = prev; | ||
this.args = args.map(autoCastToken); | ||
} | ||
CollectKeepExpression.prototype = new PartialStatement(); | ||
CollectKeepExpression.prototype.constructor = CollectKeepExpression; | ||
CollectKeepExpression.prototype.toAQL = function () { | ||
return ( | ||
(this.prev ? this.prev.toAQL() + ' ' : '') + | ||
'KEEP ' + this.args.map(wrapAQL).join(', ') | ||
); | ||
}; | ||
CollectKeepExpression.prototype.keep = CollectExpression.prototype.keep; | ||
function SortExpression(prev, args) { | ||
@@ -630,3 +669,3 @@ if (!args || !Array.isArray(args)) { | ||
RemoveExpression.prototype.options = function (opts) { | ||
return new RemoveExpressionWithOptions(this.prev, this.expr, this.collection, opts); | ||
return new OptionsExpression(this, opts); | ||
}; | ||
@@ -641,16 +680,12 @@ RemoveExpression.prototype.toAQL = function () { | ||
function RemoveExpressionWithOptions(prev, expr, collection, opts) { | ||
function OptionsExpression(prev, opts) { | ||
this.prev = prev; | ||
this.expr = autoCastToken(expr); | ||
this.collection = new Identifier(collection); | ||
this.opts = autoCastToken(opts); | ||
} | ||
RemoveExpressionWithOptions.prototype = new Statement(); | ||
RemoveExpressionWithOptions.prototype.constructor = RemoveExpressionWithOptions; | ||
RemoveExpressionWithOptions.prototype.toAQL = function () { | ||
OptionsExpression.prototype = new Statement(); | ||
OptionsExpression.prototype.constructor = OptionsExpression; | ||
OptionsExpression.prototype.toAQL = function () { | ||
return ( | ||
(this.prev ? this.prev.toAQL() + ' ' : '') + | ||
'REMOVE ' + wrapAQL(this.expr) + | ||
' IN ' + wrapAQL(this.collection) + | ||
' OPTIONS ' + wrapAQL(this.opts) | ||
'OPTIONS ' + wrapAQL(this.opts) | ||
); | ||
@@ -667,3 +702,3 @@ }; | ||
InsertExpression.prototype.options = function (opts) { | ||
return new InsertExpressionWithOptions(this.prev, this.expr, this.collection, opts); | ||
return new OptionsExpression(this, opts); | ||
}; | ||
@@ -678,19 +713,2 @@ InsertExpression.prototype.toAQL = function () { | ||
function InsertExpressionWithOptions(prev, expr, collection, opts) { | ||
this.prev = prev; | ||
this.expr = autoCastToken(expr); | ||
this.collection = new Identifier(collection); | ||
this.opts = autoCastToken(opts); | ||
} | ||
InsertExpressionWithOptions.prototype = new Statement(); | ||
InsertExpressionWithOptions.prototype.constructor = InsertExpressionWithOptions; | ||
InsertExpressionWithOptions.prototype.toAQL = function () { | ||
return ( | ||
(this.prev ? this.prev.toAQL() + ' ' : '') + | ||
'INSERT ' + wrapAQL(this.expr) + | ||
' INTO ' + wrapAQL(this.collection) + | ||
' OPTIONS ' + wrapAQL(this.opts) | ||
); | ||
}; | ||
function UpdateExpression(prev, expr, withExpr, collection) { | ||
@@ -705,3 +723,3 @@ this.prev = prev; | ||
UpdateExpression.prototype.options = function (opts) { | ||
return new UpdateExpressionWithOptions(this.prev, this.expr, this.withExpr, this.collection, opts); | ||
return new OptionsExpression(this, opts); | ||
}; | ||
@@ -717,21 +735,2 @@ UpdateExpression.prototype.toAQL = function () { | ||
function UpdateExpressionWithOptions(prev, expr, withExpr, collection, opts) { | ||
this.prev = prev; | ||
this.expr = autoCastToken(expr); | ||
this.withExpr = withExpr === undefined ? undefined : autoCastToken(withExpr); | ||
this.collection = new Identifier(collection); | ||
this.opts = autoCastToken(opts); | ||
} | ||
UpdateExpressionWithOptions.prototype = new Statement(); | ||
UpdateExpressionWithOptions.prototype.constructor = UpdateExpressionWithOptions; | ||
UpdateExpressionWithOptions.prototype.toAQL = function () { | ||
return ( | ||
(this.prev ? this.prev.toAQL() + ' ' : '') + | ||
'UPDATE ' + wrapAQL(this.expr) + | ||
(this.withExpr ? ' WITH ' + wrapAQL(this.withExpr) : '') + | ||
' IN ' + wrapAQL(this.collection) + | ||
' OPTIONS ' + wrapAQL(this.opts) | ||
); | ||
}; | ||
function ReplaceExpression(prev, expr, withExpr, collection) { | ||
@@ -746,3 +745,3 @@ this.prev = prev; | ||
ReplaceExpression.prototype.options = function (opts) { | ||
return new ReplaceExpressionWithOptions(this.prev, this.expr, this.withExpr, this.collection, opts); | ||
return new OptionsExpression(this, opts); | ||
}; | ||
@@ -758,21 +757,2 @@ ReplaceExpression.prototype.toAQL = function () { | ||
function ReplaceExpressionWithOptions(prev, expr, withExpr, collection, opts) { | ||
this.prev = prev; | ||
this.expr = autoCastToken(expr); | ||
this.withExpr = withExpr === undefined ? undefined : autoCastToken(withExpr); | ||
this.collection = new Identifier(collection); | ||
this.opts = autoCastToken(opts); | ||
} | ||
ReplaceExpressionWithOptions.prototype = new Statement(); | ||
ReplaceExpressionWithOptions.prototype.constructor = ReplaceExpressionWithOptions; | ||
ReplaceExpressionWithOptions.prototype.toAQL = function () { | ||
return ( | ||
(this.prev ? this.prev.toAQL() + ' ' : '') + | ||
'REPLACE ' + wrapAQL(this.expr) + | ||
(this.withExpr ? ' WITH ' + wrapAQL(this.withExpr) : '') + | ||
' IN ' + wrapAQL(this.collection) + | ||
' OPTIONS ' + wrapAQL(this.opts) | ||
); | ||
}; | ||
exports.autoCastToken = autoCastToken; | ||
@@ -815,5 +795,4 @@ exports.RawExpression = RawExpression; | ||
exports._CollectIntoExpression = CollectIntoExpression; | ||
exports._RemoveExpressionWithOptions = RemoveExpressionWithOptions; | ||
exports._InsertExpressionWithOptions = InsertExpressionWithOptions; | ||
exports._UpdateExpressionWithOptions = UpdateExpressionWithOptions; | ||
exports._ReplaceExpressionWithOptions = ReplaceExpressionWithOptions; | ||
exports._CollectCountExpression = CollectCountExpression; | ||
exports._CollectKeepExpression = CollectKeepExpression; | ||
exports._OptionsExpression = OptionsExpression; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
562
60509
928