MCPcopy
hub / github.com/sequelize/sequelize / set

Method set

lib/sequelize.js:664–687  ·  view source on GitHub ↗

* Execute a query which would set an environment or user variable. The variables are set per connection, so this function needs a transaction. * Only works for MySQL. * * @param {object} variables Object with multiple variables. * @param {object} [options] query options.

(variables, options)

Source from the content-addressed store, hash-verified

662 * @returns {Promise}
663 */
664 async set(variables, options) {
665
666 // Prepare options
667 options = { ...this.options.set, ...typeof options === 'object' && options };
668
669 if (this.options.dialect !== 'mysql') {
670 throw new Error('sequelize.set is only supported for mysql');
671 }
672 if (!options.transaction || !(options.transaction instanceof Transaction) ) {
673 throw new TypeError('options.transaction is required');
674 }
675
676 // Override some options, since this isn't a SELECT
677 options.raw = true;
678 options.plain = true;
679 options.type = 'SET';
680
681 // Generate SQL Query
682 const query =
683 `SET ${
684 _.map(variables, (v, k) => `@${k} := ${typeof v === 'string' ? `"${v}"` : v}`).join(', ')}`;
685
686 return await this.query(query, options);
687 }
688
689 /**
690 * Escape value.

Callers

nothing calls this directly

Calls 1

queryMethod · 0.95

Tested by

no test coverage detected