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

Method _traverseJSON

src/dialects/abstract/query-generator.js:2664–2701  ·  view source on GitHub ↗
(items, baseKey, prop, item, path)

Source from the content-addressed store, hash-verified

2662 }
2663
2664 _traverseJSON(items, baseKey, prop, item, path) {
2665 let cast;
2666
2667 if (path[path.length - 1].includes('::')) {
2668 const tmp = path[path.length - 1].split('::');
2669 cast = tmp[1];
2670 path[path.length - 1] = tmp[0];
2671
2672 this._validateCastType(cast);
2673 }
2674
2675 let pathKey = this.jsonPathExtractionQuery(baseKey, path);
2676
2677 if (_.isPlainObject(item)) {
2678 Utils.getOperators(item).forEach(op => {
2679 const value = this._toJSONValue(item[op]);
2680 let isJson = false;
2681 if (typeof value === 'string' && op === Op.contains) {
2682 try {
2683 JSON.stringify(value);
2684 isJson = true;
2685 } catch (e) {
2686 // failed to parse, is not json so isJson remains false
2687 }
2688 }
2689 pathKey = this.jsonPathExtractionQuery(baseKey, path, isJson);
2690 items.push(this.whereItemQuery(this._castKey(pathKey, value, cast), { [op]: value }));
2691 });
2692 _.forOwn(item, (value, itemProp) => {
2693 this._traverseJSON(items, baseKey, itemProp, value, path.concat([itemProp]));
2694 });
2695
2696 return;
2697 }
2698
2699 item = this._toJSONValue(item);
2700 items.push(this.whereItemQuery(this._castKey(pathKey, item, cast), { [Op.eq]: item }));
2701 }
2702
2703 _toJSONValue(value) {
2704 return value;

Callers 1

_whereJSONMethod · 0.95

Calls 6

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

Tested by

no test coverage detected