1
0
Fork 0

Handle extra args to db._query when using aql templates (#8789)

This commit is contained in:
Alan Plum 2019-04-18 10:50:46 +02:00 committed by Jan
parent 748ba14071
commit 8692f19e99
4 changed files with 53 additions and 22 deletions

View File

@ -1,6 +1,9 @@
devel
-----
* db._query now handles additional arguments correctly when passing an AQL
query object instead of a query string and separate bindVars
* added req.auth property to Foxx
* added collection.documentId method to derive document id from key

View File

@ -928,23 +928,30 @@ ArangoDatabase.prototype._createStatement = function (data) {
// //////////////////////////////////////////////////////////////////////////////
ArangoDatabase.prototype._query = function (query, bindVars, cursorOptions, options) {
if (typeof query === 'object' && query !== null && arguments.length === 1) {
return new ArangoStatement(this, query).execute();
var payload = {
query,
bindVars: bindVars || undefined
};
if (query && typeof query === 'object' && typeof query.toAQL !== 'function') {
payload = query;
options = cursorOptions;
cursorOptions = bindVars;
}
if (options === undefined && cursorOptions !== undefined) {
options = cursorOptions;
}
var data = {
query: query,
bindVars: bindVars || undefined,
count: (cursorOptions && cursorOptions.count) || false,
batchSize: (cursorOptions && cursorOptions.batchSize) || undefined,
options: options || undefined,
cache: (options && options.cache) || undefined
};
if (options) {
payload.options = options || undefined;
payload.cache = (options && options.cache) || undefined;
}
if (cursorOptions) {
payload.count = (cursorOptions && cursorOptions.count) || false;
payload.batchSize = (cursorOptions && cursorOptions.batchSize) || undefined;
}
return new ArangoStatement(this, data).execute();
return new ArangoStatement(this, payload).execute();
};
// //////////////////////////////////////////////////////////////////////////////

View File

@ -76,21 +76,29 @@ ArangoDatabase.prototype._createStatement = function (data) {
// //////////////////////////////////////////////////////////////////////////////
ArangoDatabase.prototype._query = function (query, bindVars, cursorOptions, options) {
if (typeof query === 'object' && query !== null && arguments.length === 1) {
return new ArangoStatement(this, query).execute();
var payload = {
query,
bindVars: bindVars || undefined
};
if (query && typeof query === 'object' && typeof query.toAQL !== 'function') {
payload = query;
options = cursorOptions;
cursorOptions = bindVars;
}
if (options === undefined && cursorOptions !== undefined) {
options = cursorOptions;
}
var payload = {
query: query,
bindVars: bindVars || undefined,
count: (cursorOptions && cursorOptions.count) || false,
batchSize: (cursorOptions && cursorOptions.batchSize) || undefined,
options: options || undefined,
cache: (options && options.cache) || undefined
};
if (options) {
payload.options = options || undefined;
payload.cache = (options && options.cache) || undefined;
}
if (cursorOptions) {
payload.count = (cursorOptions && cursorOptions.count) || false;
payload.batchSize = (cursorOptions && cursorOptions.batchSize) || undefined;
}
return new ArangoStatement(this, payload).execute();
};

View File

@ -164,6 +164,20 @@ function DatabaseSuite () {
assertEqual([ 1 ], internal.db._query(aql`${aql.literal('RETURN 1')}`).toArray());
},
////////////////////////////////////////////////////////////////////////////////
/// @brief test AQL literal and options
////////////////////////////////////////////////////////////////////////////////
testAQLWithLiteralAndOptions : function () {
var aql = require("@arangodb").aql;
var result = internal.db._query(
aql`${aql.literal('RETURN 1')}`,
{fullCount: true}
);
assertEqual([ 1 ], result.toArray());
assertEqual(1, result.getExtra().stats.fullCount);
},
////////////////////////////////////////////////////////////////////////////////
/// @brief test _executeTransaction
////////////////////////////////////////////////////////////////////////////////
@ -698,4 +712,3 @@ function DatabaseSuite () {
jsunity.run(DatabaseSuite);
return jsunity.done();