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