* Returns an update query * * @param {string} tableName * @param {object} attrValueHash * @param {object} where A hash with conditions (e.g. {name: 'foo'}) OR an ID as integer * @param {object} options * @param {object} attributes * * @private
(tableName, attrValueHash, where, options, attributes)
| 461 | * @private |
| 462 | */ |
| 463 | updateQuery(tableName, attrValueHash, where, options, attributes) { |
| 464 | options = options || {}; |
| 465 | _.defaults(options, this.options); |
| 466 | |
| 467 | attrValueHash = Utils.removeNullValuesFromHash(attrValueHash, options.omitNull, options); |
| 468 | |
| 469 | const values = []; |
| 470 | const bind = []; |
| 471 | const modelAttributeMap = {}; |
| 472 | let outputFragment = ''; |
| 473 | let tmpTable = ''; // tmpTable declaration for trigger |
| 474 | let suffix = ''; |
| 475 | |
| 476 | if (_.get(this, ['sequelize', 'options', 'dialectOptions', 'prependSearchPath']) || options.searchPath) { |
| 477 | // Not currently supported with search path (requires output of multiple queries) |
| 478 | options.bindParam = false; |
| 479 | } |
| 480 | |
| 481 | const bindParam = options.bindParam === undefined ? this.bindParam(bind) : options.bindParam; |
| 482 | |
| 483 | if (this._dialect.supports['LIMIT ON UPDATE'] && options.limit) { |
| 484 | if (!['mssql', 'db2', 'oracle'].includes(this.dialect)) { |
| 485 | suffix = ` LIMIT ${this.escape(options.limit)} `; |
| 486 | } else if (this.dialect === 'oracle') { |
| 487 | // This cannot be setted in where because rownum will be quoted |
| 488 | if (where && (where.length && where.length > 0 || Object.keys(where).length > 0)) { |
| 489 | // If we have a where clause, we add AND |
| 490 | suffix += ' AND '; |
| 491 | } else { |
| 492 | // No where clause, we add where |
| 493 | suffix += ' WHERE '; |
| 494 | } |
| 495 | suffix += `rownum <= ${this.escape(options.limit)} `; |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | if (this._dialect.supports.returnValues && options.returning) { |
| 500 | const returnValues = this.generateReturnValues(attributes, options); |
| 501 | |
| 502 | suffix += returnValues.returningFragment; |
| 503 | tmpTable = returnValues.tmpTable || ''; |
| 504 | outputFragment = returnValues.outputFragment || ''; |
| 505 | |
| 506 | // ensure that the return output is properly mapped to model fields. |
| 507 | if (!this._dialect.supports.returnValues.output && options.returning) { |
| 508 | options.mapToModel = true; |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | if (attributes) { |
| 513 | _.each(attributes, (attribute, key) => { |
| 514 | modelAttributeMap[key] = attribute; |
| 515 | if (attribute.field) { |
| 516 | modelAttributeMap[attribute.field] = attribute; |
| 517 | } |
| 518 | }); |
| 519 | } |
| 520 |
no test coverage detected