MCPcopy Index your code
hub / github.com/scality/cloudserver / parseWhere

Function parseWhere

lib/api/apiUtils/bucket/parseWhere.js:48–81  ·  view source on GitHub ↗
(root)

Source from the content-addressed store, hash-verified

46 * and generates MongoDB `find` query object
47 */
48function parseWhere(root) {
49 const operator = Object.keys(root)[0];
50
51 // extract leaf binary expressions
52 if (operator === 'AND') {
53 const e1 = parseWhere(root[operator][0]);
54 const e2 = parseWhere(root[operator][1]);
55
56 return { '$and' : [
57 e1,
58 e2,
59 ] };
60 } else if (operator === 'OR') {
61 const e1 = parseWhere(root[operator][0]);
62 const e2 = parseWhere(root[operator][1]);
63
64 return { '$or' : [
65 e1,
66 e2,
67 ] };
68 }
69 const field = root[operator][0];
70 const value = root[operator][1];
71 const expr = exprMapper[operator];
72 const obj = {};
73
74 if (operator === 'LIKE') {
75 obj[`value.${field}`] = parseLikeExpression(value);
76 } else {
77 obj[`value.${field}`] = { [expr]: value };
78 }
79
80 return obj;
81}
82
83module.exports = parseWhere;

Callers 1

metadataSearchFunction · 0.85

Calls 1

parseLikeExpressionFunction · 0.85

Tested by

no test coverage detected