MCPcopy
hub / github.com/sequelize/sequelize / updateQuery

Method updateQuery

lib/dialects/abstract/query-generator.js:365–443  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

363 * @private
364 */
365 updateQuery(tableName, attrValueHash, where, options, attributes) {
366 options = options || {};
367 _.defaults(options, this.options);
368
369 attrValueHash = Utils.removeNullValuesFromHash(attrValueHash, options.omitNull, options);
370
371 const values = [];
372 const bind = [];
373 const modelAttributeMap = {};
374 let outputFragment = '';
375 let tmpTable = ''; // tmpTable declaration for trigger
376 let suffix = '';
377
378 if (_.get(this, ['sequelize', 'options', 'dialectOptions', 'prependSearchPath']) || options.searchPath) {
379 // Not currently supported with search path (requires output of multiple queries)
380 options.bindParam = false;
381 }
382
383 const bindParam = options.bindParam === undefined ? this.bindParam(bind) : options.bindParam;
384
385 if (this._dialect.supports['LIMIT ON UPDATE'] && options.limit) {
386 if (this.dialect !== 'mssql' && this.dialect !== 'db2') {
387 suffix = ` LIMIT ${this.escape(options.limit)} `;
388 }
389 }
390
391 if (this._dialect.supports.returnValues && options.returning) {
392 const returnValues = this.generateReturnValues(attributes, options);
393
394 suffix += returnValues.returningFragment;
395 tmpTable = returnValues.tmpTable || '';
396 outputFragment = returnValues.outputFragment || '';
397
398 // ensure that the return output is properly mapped to model fields.
399 if (!this._dialect.supports.returnValues.output && options.returning) {
400 options.mapToModel = true;
401 }
402 }
403
404 if (attributes) {
405 _.each(attributes, (attribute, key) => {
406 modelAttributeMap[key] = attribute;
407 if (attribute.field) {
408 modelAttributeMap[attribute.field] = attribute;
409 }
410 });
411 }
412
413 for (const key in attrValueHash) {
414 if (modelAttributeMap && modelAttributeMap[key] &&
415 modelAttributeMap[key].autoIncrement === true &&
416 !this._dialect.supports.autoIncrement.update) {
417 // not allowed to update identity column
418 continue;
419 }
420
421 const value = attrValueHash[key];
422

Callers 2

updateMethod · 0.45
bulkUpdateMethod · 0.45

Calls 8

bindParamMethod · 0.95
escapeMethod · 0.95
generateReturnValuesMethod · 0.95
quoteIdentifierMethod · 0.95
formatMethod · 0.95
quoteTableMethod · 0.95
whereQueryMethod · 0.95
getMethod · 0.65

Tested by

no test coverage detected