MCPcopy Index your code
hub / github.com/sequelize/sequelize / updateQuery

Method updateQuery

src/dialects/db2/query-generator.js:359–401  ·  view source on GitHub ↗
(tableName, attrValueHash, where, options, attributes)

Source from the content-addressed store, hash-verified

357 }
358
359 updateQuery(tableName, attrValueHash, where, options, attributes) {
360 const sql = super.updateQuery(tableName, attrValueHash, where, options, attributes);
361 options = options || {};
362 _.defaults(options, this.options);
363 if ( ! options.limit ) {
364 sql.query = `SELECT * FROM FINAL TABLE (${ sql.query });`;
365 return sql;
366 }
367
368 attrValueHash = Utils.removeNullValuesFromHash(attrValueHash, options.omitNull, options);
369
370 const modelAttributeMap = {};
371 const values = [];
372 const bind = [];
373 const bindParam = options.bindParam || this.bindParam(bind);
374
375 if (attributes) {
376 _.each(attributes, (attribute, key) => {
377 modelAttributeMap[key] = attribute;
378 if (attribute.field) {
379 modelAttributeMap[attribute.field] = attribute;
380 }
381 });
382 }
383
384 for (const key in attrValueHash) {
385 const value = attrValueHash[key];
386
387 if (value instanceof Utils.SequelizeMethod || options.bindParam === false)
388 {
389 values.push(`${this.quoteIdentifier(key) }=${ this.escape(value, modelAttributeMap && modelAttributeMap[key] || undefined, { context: 'UPDATE' })}`);
390 } else {
391 values.push(`${this.quoteIdentifier(key) }=${ this.format(value, modelAttributeMap && modelAttributeMap[key] || undefined, { context: 'UPDATE' }, bindParam)}`);
392 }
393 }
394
395 let query;
396 const whereOptions = _.defaults({ bindParam }, options);
397
398 query = `UPDATE (SELECT * FROM ${this.quoteTable(tableName)} ${this.whereQuery(where, whereOptions)} FETCH NEXT ${this.escape(options.limit)} ROWS ONLY) SET ${values.join(',')}`;
399 query = `SELECT * FROM FINAL TABLE (${ query });`;
400 return { query, bind };
401 }
402
403 upsertQuery(tableName, insertValues, updateValues, where, model) {
404 const targetTableAlias = this.quoteTable(`${tableName}_target`);

Callers 2

update.test.jsFile · 0.45
upsertQueryMethod · 0.45

Calls 6

quoteIdentifierMethod · 0.95
formatMethod · 0.80
quoteTableMethod · 0.80
whereQueryMethod · 0.80
bindParamMethod · 0.45
escapeMethod · 0.45

Tested by

no test coverage detected