MCPcopy
hub / github.com/sequelize/sequelize / _traverseJSON

Method _traverseJSON

lib/dialects/abstract/query-generator.js:2487–2522  ·  lib/dialects/abstract/query-generator.js::QueryGenerator._traverseJSON
(items, baseKey, prop, item, path)

Source from the content-addressed store, hash-verified

2485 }
2486
2487 _traverseJSON(items, baseKey, prop, item, path) {
2488 let cast;
2489
2490 if (path[path.length - 1].includes(class="st">'::')) {
2491 const tmp = path[path.length - 1].split(class="st">'::');
2492 cast = tmp[1];
2493 path[path.length - 1] = tmp[0];
2494 }
2495
2496 let pathKey = this.jsonPathExtractionQuery(baseKey, path);
2497
2498 if (_.isPlainObject(item)) {
2499 Utils.getOperators(item).forEach(op => {
2500 const value = this._toJSONValue(item[op]);
2501 let isJson = false;
2502 if (typeof value === class="st">'string' && op === Op.contains) {
2503 try {
2504 JSON.stringify(value);
2505 isJson = true;
2506 } catch (e) {
2507 class="cm">// failed to parse, is not json so isJson remains false
2508 }
2509 }
2510 pathKey = this.jsonPathExtractionQuery(baseKey, path, isJson);
2511 items.push(this.whereItemQuery(this._castKey(pathKey, value, cast), { [op]: value }));
2512 });
2513 _.forOwn(item, (value, itemProp) => {
2514 this._traverseJSON(items, baseKey, itemProp, value, path.concat([itemProp]));
2515 });
2516
2517 return;
2518 }
2519
2520 item = this._toJSONValue(item);
2521 items.push(this.whereItemQuery(this._castKey(pathKey, item, cast), { [Op.eq]: item }));
2522 }
2523
2524 _toJSONValue(value) {
2525 return value;

Callers 1

_whereJSONMethod · 0.95

Calls 5

_toJSONValueMethod · 0.95
whereItemQueryMethod · 0.95
_castKeyMethod · 0.95
stringifyMethod · 0.65

Tested by

no test coverage detected