adds ability to set hint on Parse.Query #6288 (#6322)

* added hint to aggregate

* added support for hint in query

* added else clause to aggregate

* fixed tests

* updated tests

* Add tests and clean up

* Add support for explain

Co-authored-by: Diamond Lewis <findlewis@gmail.com>
This commit is contained in:
stevestencil
2020-01-14 01:14:43 -07:00
committed by Diamond Lewis
parent 5a1d94ed88
commit 9842c6ee42
9 changed files with 267 additions and 21 deletions

View File

@@ -4,7 +4,7 @@ import * as middleware from '../middlewares';
import Parse from 'parse/node';
import UsersRouter from './UsersRouter';
const BASE_KEYS = ['where', 'distinct', 'pipeline'];
const BASE_KEYS = ['where', 'distinct', 'pipeline', 'hint', 'explain'];
const PIPELINE_KEYS = [
'addFields',
@@ -46,6 +46,14 @@ export class AggregateRouter extends ClassesRouter {
if (body.distinct) {
options.distinct = String(body.distinct);
}
if (body.hint) {
options.hint = body.hint;
delete body.hint;
}
if (body.explain) {
options.explain = body.explain;
delete body.explain;
}
options.pipeline = AggregateRouter.getPipeline(body);
if (typeof body.where === 'string') {
body.where = JSON.parse(body.where);
@@ -96,7 +104,6 @@ export class AggregateRouter extends ClassesRouter {
*/
static getPipeline(body) {
let pipeline = body.pipeline || body;
if (!Array.isArray(pipeline)) {
pipeline = Object.keys(pipeline).map(key => {
return { [key]: pipeline[key] };

View File

@@ -173,6 +173,8 @@ export class ClassesRouter extends PromiseRouter {
'readPreference',
'includeReadPreference',
'subqueryReadPreference',
'hint',
'explain',
];
for (const key of Object.keys(body)) {
@@ -219,6 +221,15 @@ export class ClassesRouter extends PromiseRouter {
if (typeof body.subqueryReadPreference === 'string') {
options.subqueryReadPreference = body.subqueryReadPreference;
}
if (
body.hint &&
(typeof body.hint === 'string' || typeof body.hint === 'object')
) {
options.hint = body.hint;
}
if (body.explain) {
options.explain = body.explain;
}
return options;
}