| 2299 | } |
| 2300 | |
| 2301 | whereItemQuery(key, value, options = {}) { |
| 2302 | if (value === undefined) { |
| 2303 | throw new Error(`WHERE parameter class="st">"${key}" has invalid class="st">"undefined" value`); |
| 2304 | } |
| 2305 | |
| 2306 | if (typeof key === class="st">'string' && key.includes(class="st">'.') && options.model) { |
| 2307 | const keyParts = key.split(class="st">'.'); |
| 2308 | if (options.model.rawAttributes[keyParts[0]] && options.model.rawAttributes[keyParts[0]].type instanceof DataTypes.JSON) { |
| 2309 | const tmp = {}; |
| 2310 | const field = options.model.rawAttributes[keyParts[0]]; |
| 2311 | _.set(tmp, keyParts.slice(1), value); |
| 2312 | return this.whereItemQuery(field.field || keyParts[0], tmp, { field, ...options }); |
| 2313 | } |
| 2314 | } |
| 2315 | |
| 2316 | const field = this._findField(key, options); |
| 2317 | const fieldType = field && field.type || options.type; |
| 2318 | |
| 2319 | const isPlainObject = _.isPlainObject(value); |
| 2320 | const isArray = !isPlainObject && Array.isArray(value); |
| 2321 | key = this.OperatorsAliasMap && this.OperatorsAliasMap[key] || key; |
| 2322 | if (isPlainObject) { |
| 2323 | value = this._replaceAliases(value); |
| 2324 | } |
| 2325 | const valueKeys = isPlainObject && Utils.getComplexKeys(value); |
| 2326 | |
| 2327 | if (key === undefined) { |
| 2328 | if (typeof value === class="st">'string') { |
| 2329 | return value; |
| 2330 | } |
| 2331 | |
| 2332 | if (isPlainObject && valueKeys.length === 1) { |
| 2333 | return this.whereItemQuery(valueKeys[0], value[valueKeys[0]], options); |
| 2334 | } |
| 2335 | } |
| 2336 | |
| 2337 | if (value === null) { |
| 2338 | const opValue = options.bindParam ? class="st">'NULL' : this.escape(value, field); |
| 2339 | return this._joinKeyValue(key, opValue, this.OperatorMap[Op.is], options.prefix); |
| 2340 | } |
| 2341 | |
| 2342 | if (!value) { |
| 2343 | const opValue = options.bindParam ? this.format(value, field, options, options.bindParam) : this.escape(value, field); |
| 2344 | return this._joinKeyValue(key, opValue, this.OperatorMap[Op.eq], options.prefix); |
| 2345 | } |
| 2346 | |
| 2347 | if (value instanceof Utils.SequelizeMethod && !(key !== undefined && value instanceof Utils.Fn)) { |
| 2348 | return this.handleSequelizeMethod(value); |
| 2349 | } |
| 2350 | |
| 2351 | class="cm">// Convert where: [] to Op.and if possible, else treat as literal/replacements |
| 2352 | if (key === undefined && isArray) { |
| 2353 | if (Utils.canTreatArrayAsAnd(value)) { |
| 2354 | key = Op.and; |
| 2355 | } else { |
| 2356 | throw new Error(class="st">'Support for literal replacements in the `where` object has been removed.'); |
| 2357 | } |
| 2358 | } |